{"id":89,"date":"2019-10-07T11:32:05","date_gmt":"2019-10-07T11:32:05","guid":{"rendered":"https:\/\/docs.theironnetwork.org\/embryo\/?page_id=89"},"modified":"2019-10-15T09:45:05","modified_gmt":"2019-10-15T09:45:05","slug":"adding-new-widgets","status":"publish","type":"page","link":"https:\/\/docs.theironnetwork.org\/embryo\/adding-new-widgets\/","title":{"rendered":"Adding New Widgets"},"content":{"rendered":"\n<h5 id=\"adding-a-new-widget\">Adding a new widget<\/h5>\n\n\n\n<p>Please follow the given steps to add a new widget in the template. We are taking an example of adding a &#8220;Blog Section&#8221; on the &#8220;Home Page Two&#8221; but you can add any widget on any of the pages in the template:\u200c<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> Go to <code>src-&gt;routes-&gt;home-two<\/code> &amp; open the <code>index.js<\/code> file and add the widget in the file like below. You can also add some styling to it, for this you can take the reference from other pages.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{\/ blog grid section start \/}<br>    &lt; div className=\"section-pad pt-0\" &gt;<br>         &lt;div className=\"container\"&gt;<br>            \/\/ Add some basic styling here<br>            &lt;BlogGrid \/&gt; \/\/ Added Blog Grid Widget<br>         &lt;\/div&gt;<br>    &lt;\/div &gt;<\/pre>\n\n\n\n<p>and import the widget at the top of the file like other import statements:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import BlogGrid from '..\/..\/components\/widgets\/BlogGrid3';<\/pre>\n\n\n\n<p><strong>Step 2:<\/strong> Now you have to define a new state. This state is used to pass the data to the grid.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">constructor(props) {<br>      super(props);<br>      this.state = {<br>        ...<br>         blogs: null \/\/ New State Defined<br>      }<br>   }<br>\u200c<br><\/pre>\n\n\n\n<p><strong>Step 3:<\/strong> Now you have to create a function to fetch the data from your database (in our case we are fetching the data from firebase) and pass it to the state defined in above step.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/get blogs data<br>   getblogs() {<br>      const blogsRef = firebase.database().ref('blogs');<br>      blogsRef.on('value', (snapshot) =&gt; {<br>         let blogs = snapshot.val();<br>         this.setState({<br>            blogs: blogs \/\/ Set the state<br>         });<br>      });<br>   }<\/pre>\n\n\n\n<p>We need to import the firebase in our case.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ firebase<br>import firebase from '..\/..\/firebase';<br>import 'firebase\/database';<\/pre>\n\n\n\n<p><strong>Step 4:<\/strong> Call this function in the <code>componentDidMount()<\/code> method.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">componentDidMount() {<br>     ...<br>      this.getblogs();<br>   }<\/pre>\n\n\n\n<p><strong>Step 5: <\/strong>You have to conditionalise the return statement so that it will only return when your state have some data to show on the blog grid.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">return (<br>         &lt;Fragment&gt;<br>            {<br>               ... &amp;&amp; this.state.blogs !== null ?<br>                  &lt;div className=\"iron-home-v2-wrap\"&gt;<br>                     ...<br>                     &lt;BlogGrid blogItems={this.state.blogs} \/&gt;<\/pre>\n\n\n\n<p>Once you have completed the above steps, you can now check the newly added widget on your Home Two Page like below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" width=\"1024\" height=\"538\" src=\"https:\/\/docs.theironnetwork.org\/embryo\/wp-content\/uploads\/sites\/7\/2019\/10\/blog-1024x538.png\" alt=\"\" class=\"wp-image-94\" srcset=\"https:\/\/docs.theironnetwork.org\/embryo\/wp-content\/uploads\/sites\/7\/2019\/10\/blog-1024x538.png 1024w, https:\/\/docs.theironnetwork.org\/embryo\/wp-content\/uploads\/sites\/7\/2019\/10\/blog-300x158.png 300w, https:\/\/docs.theironnetwork.org\/embryo\/wp-content\/uploads\/sites\/7\/2019\/10\/blog-768x403.png 768w, https:\/\/docs.theironnetwork.org\/embryo\/wp-content\/uploads\/sites\/7\/2019\/10\/blog-1568x824.png 1568w, https:\/\/docs.theironnetwork.org\/embryo\/wp-content\/uploads\/sites\/7\/2019\/10\/blog.png 1856w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<div class=\"pld-like-dislike-wrap pld-template-1\">\n    <div class=\"pld-like-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0);\" class=\"pld-like-trigger pld-like-dislike-trigger \" title=\"\" data-post-id=\"89\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-ip-check=\"0\" data-user-check=\"1\">\n                        <i class=\"fas fa-thumbs-up\"><\/i>\n                    <\/a>\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\n    <a href=\"javascript:void(0);\" class=\"pld-dislike-trigger pld-like-dislike-trigger \" title=\"\" data-post-id=\"89\" data-trigger-type=\"dislike\" data-ip-check=\"0\" data-restriction=\"cookie\" data-user-check=\"1\">\n                        <i class=\"fas fa-thumbs-down\"><\/i>\n                    <\/a>\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\n<\/div><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Adding a new widget Please follow the given steps to add a new widget in the template. We are taking an example of adding a &#8220;Blog Section&#8221; on the &#8220;Home Page Two&#8221; but you can add any widget on any of the pages in the template:\u200c Step 1: Go to src-&gt;routes-&gt;home-two &amp; open the index.js [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":15,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/docs.theironnetwork.org\/embryo\/wp-json\/wp\/v2\/pages\/89"}],"collection":[{"href":"https:\/\/docs.theironnetwork.org\/embryo\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/docs.theironnetwork.org\/embryo\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/docs.theironnetwork.org\/embryo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.theironnetwork.org\/embryo\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":7,"href":"https:\/\/docs.theironnetwork.org\/embryo\/wp-json\/wp\/v2\/pages\/89\/revisions"}],"predecessor-version":[{"id":293,"href":"https:\/\/docs.theironnetwork.org\/embryo\/wp-json\/wp\/v2\/pages\/89\/revisions\/293"}],"wp:attachment":[{"href":"https:\/\/docs.theironnetwork.org\/embryo\/wp-json\/wp\/v2\/media?parent=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}