{"id":282419,"date":"2021-02-09T06:26:17","date_gmt":"2021-02-09T06:26:17","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=282419"},"modified":"2024-08-01T09:32:03","modified_gmt":"2024-08-01T09:32:03","slug":"magento-2-collection-list-block","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/","title":{"rendered":"Magento 2: Collection List and Block"},"content":{"rendered":"\n<p>Now that we have saved the form data in <a href=\"https:\/\/business.adobe.com\/in\/products\/magento\/magento-commerce.html\">Magento<\/a>, let&#8217;s create a list where customers can view all of his\/her blogs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Redirection and Messages<\/h2>\n\n\n\n<p>Earlier we displayed just a simple message saying &#8220;Saved&#8221; when the customer submitted the form. But it will be better to redirect to the list page after saving the data. <\/p>\n\n\n\n<p>So we have to edit the <em>Controller\/Manage\/Save.php<\/em> file,<\/p>\n\n\n\n<p>Updated code for <em>Controller\/Manage\/Save.php<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\BlogManager\\Controller\\Manage;\n\nuse Magento\\Customer\\Controller\\AbstractAccount;\nuse Magento\\Framework\\App\\Action\\Context;\nuse Magento\\Customer\\Model\\Session;\n\nclass Save extends AbstractAccount\n{\n    \/**\n     * @var \\Webkul\\BlogManager\\Model\\BlogFactory\n     *\/\n    protected $blogFactory;\n\n    \/**\n     * @var Magento\\Customer\\Model\\Session\n     *\/\n    protected $customerSession;\n\n    \/**\n     * @var \\Magento\\Framework\\Message\\ManagerInterface\n     *\/\n    protected $messageManager;\n\n    \/**\n     * Dependency Initilization\n     *\n     * @param Context $context\n     * @param \\Webkul\\BlogManager\\Model\\BlogFactory $blogFactory\n     *\/\n    public function __construct(\n        Context $context,\n        \\Webkul\\BlogManager\\Model\\BlogFactory $blogFactory,\n        Session $customerSession,\n        \\Magento\\Framework\\Message\\ManagerInterface $messageManager\n    ) {\n        $this-&gt;blogFactory = $blogFactory;\n        $this-&gt;customerSession = $customerSession;\n        $this-&gt;messageManager = $messageManager;\n        parent::__construct($context);\n    }\n\n    \/**\n     * Provides content\n     *\n     * @return \\Magento\\Framework\\View\\Result\\Page\n     *\/\n    public function execute()\n    {\n        $data = $this-&gt;getRequest()-&gt;getParams();\n        $model = $this-&gt;blogFactory-&gt;create();\n        $model-&gt;setData($data);\n\n        $customer = $this-&gt;customerSession-&gt;getCustomer();\n        $customerId = $customer-&gt;getId();\n        $model-&gt;setUserId($customerId);\n\n        $model-&gt;save();\n        \n        $this-&gt;messageManager-&gt;addSuccess(__(&#039;Blog saved successfully.&#039;));\n        return $this-&gt;resultRedirectFactory-&gt;create()-&gt;setPath(&#039;blog\/manage&#039;);\n    }\n}<\/pre>\n\n\n\n<p>It&#8217;s a good practice to declare the member variables. So we declared them at the start of the class. To redirect we have used resultRedirectFactory and called the setPath method with the URL at which we want to redirect.<\/p>\n\n\n\n<p> As you may have noticed here we have given only two parts of the url that&#8217;s because it will autofill the missing part with &#8220;index&#8221;. So our URL will become <em>blog\/manage\/index<\/em>.<\/p>\n\n\n\n<p>Now let&#8217;s talk about <em>\\Magento\\Framework\\Message\\ManagerInterface<\/em> class. This is used to show messages on the page. There are four types of messages available in Magento. <br>i) Success<br>ii) Error<br>iii) Notice<br>iv) Warning<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"194\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-1200x194.png\" alt=\"2021-02-08_18-54-1\" class=\"wp-image-282451\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-1200x194.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-300x48.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-250x40.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-768x124.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-1536x248.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1.png 1665w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Also, notice that in the addSuccess method, we have passed the message enclosed in <strong>__(&#8220;&#8221;)<\/strong>. All static text should be enclosed within <em>__(&#8216;some text&#8217;) <\/em>so that it become translatable. Magento allows us to create translations for different languages with the help of a .csv file.<\/p>\n\n\n\n<p>Now let&#8217;s create the index action in <em>Contoller\/Manage<\/em>\/<em>Index.php<\/em> which will be used to show the blogs list.<\/p>\n\n\n\n<p>Code for <em>Contoller\/Manage<\/em>\/<em>Index.php<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\BlogManager\\Controller\\Manage;\n\nuse Magento\\Customer\\Controller\\AbstractAccount;\nuse Magento\\Framework\\App\\Action\\Context;\nuse Magento\\Framework\\View\\Result\\PageFactory;\n\nclass Index extends AbstractAccount\n{\n    \/**\n     * @var Magento\\Framework\\View\\Result\\PageFactory\n     *\/\n    protected $resultPageFactory;\n\n    \/**\n     * Dependency Initilization\n     *\n     * @param Context $context\n     * @param PageFactory $resultPageFactory\n     *\/\n    public function __construct(\n        Context $context,\n\t    PageFactory $resultPageFactory\n    ) {\n\t    $this-&gt;resultPageFactory = $resultPageFactory;\n        parent::__construct($context);\n    }\n\n    \/**\n     * Provides content\n     *\n     * @return \\Magento\\Framework\\View\\Result\\Page\n     *\/\n    public function execute()\n    {\n        $resultPage = $this-&gt;resultPageFactory-&gt;create();\n        $resultPage-&gt;getConfig()-&gt;getTitle()-&gt;set(__(&#039;Blogs&#039;));\n        $layout = $resultPage-&gt;getLayout();\n        return $resultPage;\n    }\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Blocks<\/h2>\n\n\n\n<p>Here we will be showing a phtml file so we need to create a layout file as <strong>view\/frontend\/layout\/blogmanager_manage_index.xml<\/strong><\/p>\n\n\n\n<p>Code for <em>view\/frontend\/layout\/blogmanager_manage_index.xml<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;page xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd&quot;&gt;\n    &lt;update handle=&quot;customer_account&quot;\/&gt;\n    &lt;body&gt;\n        &lt;referenceContainer name=&quot;content&quot;&gt;\n            &lt;block class=&quot;Webkul\\BlogManager\\Block\\BlogList&quot; name=&quot;blogmanager.blog.list&quot; template=&quot;Webkul_BlogManager::list.phtml&quot; \/&gt;\n        &lt;\/referenceContainer&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;<\/pre>\n\n\n\n<p>Here everything should be familiar except the block class. Earlier we used the default block class for the Blog Add page but for the Blog List page, we will create a Block class <em>Webkul\\BlogManager\\Block\\BlogList<\/em>.<\/p>\n\n\n\n<p>Why do we need a block? The need for the block is to pass data to the template file. The block class contains the logical part of the view. <\/p>\n\n\n\n<p>All the data needed by the template file should come from the block. We do not write complex code in the phtml file, instead, we write the complex codes in the block and pass the result to the phtml file.<\/p>\n\n\n\n<p>Now let&#8217;s create the <strong>Block<\/strong> folder under the module directory. In the Block folder, we need to create the block file <strong>BlogList.php<\/strong> as<\/p>\n\n\n\n<p>Code for <em>Block\/BlogList.php<\/em> file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Webkul\\BlogManager\\Block;\n\nclass BlogList extends \\Magento\\Framework\\View\\Element\\Template\n{\n    \/**\n     * @var \\Webkul\\BlogManager\\Model\\ResourceModel\\Blog\\CollectionFactory\n     *\/\n    protected $blogCollection;\n\n    \/**\n     * Dependency Initilization\n     *\n     * @param \\Magento\\Framework\\View\\Element\\Template\\Context $context\n     * @param \\Webkul\\BlogManager\\Model\\ResourceModel\\Blog\\CollectionFactory $blogCollection\n     * @param array $data\n     *\/\n    public function __construct(\n        \\Magento\\Framework\\View\\Element\\Template\\Context $context,\n        \\Webkul\\BlogManager\\Model\\ResourceModel\\Blog\\CollectionFactory $blogCollection,\n        array $data = &#091;]\n    ) {\n        $this-&gt;blogCollection = $blogCollection;\n        parent::__construct($context, $data);\n    }\n\n    \/**\n     * Get Blog List\n     *\n     * @return \\Webkul\\BlogManager\\Model\\ResourceModel\\Blog\\Collection\n     *\/\n    public function getBlogs()\n    {\n        $collection = $this-&gt;blogCollection-&gt;create();\n        return $collection;\n    }\n}<\/pre>\n\n\n\n<p>All Blocks must extend the default block class <em>\\Magento\\Framework\\View\\Element\\Template<\/em>. We will use this block to load the blog data. <\/p>\n\n\n\n<p>Note here we are using the collection <em>\\Webkul\\BlogManager\\Model\\ResourceModel\\Blog\\CollectionFactory<\/em> because we need to load multiple rows from the table. Just like the model the model collection also has the factory class.<\/p>\n\n\n\n<p>Here we have the getBlogs() method in which we are loading the collection and returning the whole collection.  Just like the model factory here also we need to call the<em> create() <\/em>method to create a new object of the collection.<\/p>\n\n\n\n<p>Now that we have created the block let&#8217;s create the <strong>list.phtml <\/strong>file for this block under the <strong>view\/frontend\/templates <\/strong>folder.<\/p>\n\n\n\n<p>Code for <em>view\/frontend\/templates\/list.phtml <\/em>file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;table&gt;\n    &lt;tr&gt;\n        &lt;th&gt;\n            &lt;?= __(&quot;Id&quot;)?&gt;\n        &lt;\/th&gt;\n        &lt;th&gt;\n            &lt;?= __(&quot;Title&quot;)?&gt;\n        &lt;\/th&gt;\n        &lt;th&gt;\n            &lt;?= __(&quot;Content&quot;)?&gt;\n        &lt;\/th&gt;\n    &lt;\/tr&gt;\n    &lt;?php\n    $blogs = $block-&gt;getBlogs();\n\n    foreach ($blogs as $blog) {?&gt;\n    &lt;tr&gt;\n        &lt;td&gt;\n            &lt;?= $escaper-&gt;escapeHtml($blog-&gt;getId())?&gt;\n        &lt;\/td&gt;\n        &lt;td&gt;\n            &lt;?= $escaper-&gt;escapeHtml($blog-&gt;getTitle())?&gt;\n        &lt;\/td&gt;\n        &lt;td&gt;\n            &lt;?= substr($escaper-&gt;escapeHtml($blog-&gt;getContent()), 0, 20).&#039;...&#039;?&gt;\n        &lt;\/td&gt;\n    &lt;\/tr&gt;\n    &lt;?php } ?&gt;\n&lt;\/table&gt;<\/pre>\n\n\n\n<p>The <strong>&lt;?= ?&gt;<\/strong> is nothing but a shorthand notation for<strong> &lt;?php echo ?&gt;<\/strong>. You can find it in the PHP manual. I have already told you about the <strong>__(&#8220;&#8221;)<\/strong>, it&#8217;s used for translation and <strong>$escaper-&gt;escapeHtml()<\/strong> is used to remove any HTML content from the data.<\/p>\n\n\n\n<p>Now see the important line <strong>$blogs = $block->getBlogs();<\/strong> here we are calling the<strong> getBlogs()<\/strong> function of the block which will return the blogs collection. <\/p>\n\n\n\n<p>Remember I told you that collection is a collection of models, so when we loop over the collection with a foreach loop then we will get a model in each iteration. That means in each iteration we will get a row from the table.<\/p>\n\n\n\n<p>The <strong>$blog-&gt;getId()<\/strong> will return the <em>entity_id<\/em> which means it acts as <strong>getEntityId()<\/strong> that&#8217;s because in the model we have written this method,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"564\" height=\"135\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_20-32.png\" alt=\"2021-02-08_20-32\" class=\"wp-image-282459\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_20-32.png 564w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_20-32-300x72.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_20-32-250x60.png 250w\" sizes=\"(max-width: 564px) 100vw, 564px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Just like the setters that we saw in the previous blog, the getters get internally managed, we just have to use the camelCase naming convention for each column.<\/p>\n\n\n\n<p>So we can use getTitle(), and <em>getContent()<\/em> to access the title and content column respectively, even though we have not written these methods in the model file.<\/p>\n\n\n\n<p>Now when you submit the add blog form you will be redirected to the blog list page with a success message like,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"604\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_17-51-1200x604.png\" alt=\"2021-02-08_17-51\" class=\"wp-image-282460\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_17-51-1200x604.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_17-51-300x151.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_17-51-250x126.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_17-51-768x387.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_17-51-1536x774.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_17-51.png 1630w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Let&#8217;s create a customer navigation link for this page also, we have to edit <em>view\/frontend\/layout<\/em>\/<em>customer_account.xml<\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;page xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd&quot;&gt;\n    &lt;body&gt;\n        &lt;referenceBlock name=&quot;customer_account_navigation&quot;&gt;\n            &lt;block class=&quot;Magento\\Framework\\View\\Element\\Html\\Link\\Current&quot; name=&quot;customer-account-navigation-blog-add&quot; after=&quot;-&quot; &gt;\n                &lt;arguments&gt;\n                    &lt;argument name=&quot;label&quot; xsi:type=&quot;string&quot; translate=&quot;true&quot;&gt;Add Blog&lt;\/argument&gt;\n                    &lt;argument name=&quot;path&quot; xsi:type=&quot;string&quot;&gt;blog\/manage\/add&lt;\/argument&gt;\n                &lt;\/arguments&gt;\n            &lt;\/block&gt;\n            &lt;block class=&quot;Magento\\Framework\\View\\Element\\Html\\Link\\Current&quot; name=&quot;customer-account-navigation-blog-list&quot; before=&quot;customer-account-navigation-blog-add&quot; &gt;\n                &lt;arguments&gt;\n                    &lt;argument name=&quot;label&quot; xsi:type=&quot;string&quot; translate=&quot;true&quot;&gt;Blogs&lt;\/argument&gt;\n                    &lt;argument name=&quot;path&quot; xsi:type=&quot;string&quot;&gt;blog\/manage&lt;\/argument&gt;\n                &lt;\/arguments&gt;\n            &lt;\/block&gt;\n        &lt;\/referenceBlock&gt;\n    &lt;\/body&gt;\n&lt;\/page&gt;<\/pre>\n\n\n\n<p>Here in the block node, we have added <em>before=&#8221;customer-account-navigation-blog-add&#8221;<\/em> so it will add the blog list menu before the blog add menu. You will be able to see the Blogs link in the customer navigation,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"592\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-09_11-43-1200x592.png\" alt=\"2021-02-09_11-43\" class=\"wp-image-282467\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-09_11-43-1200x592.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-09_11-43-300x148.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-09_11-43-250x123.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-09_11-43-768x379.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-09_11-43-1536x758.png 1536w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-09_11-43.png 1586w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>PS. We can get the collection from the model class also. When we call the <strong>$model-&gt;getCollection()<\/strong> it returns the collection of the model.<\/p>\n\n\n\n<p>PS. Just like setData the model and collections have <em>getData<\/em>, which returns the data in associative array format. So during development or debugging when we have to view data, we use <strong>echo &#8216;&lt;pre&gt;; print_r($collection-&gt;getData()); die;<\/strong> which prints out the data in a nice viewable format.<\/p>\n\n\n\n<p>Folder structure till now,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"519\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_109-1200x519.png\" alt=\"Selection_109\" class=\"wp-image-390814\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_109-1200x519.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_109-300x130.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_109-250x108.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_109-768x332.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_109.png 1503w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Next Blog -&gt; <a href=\"https:\/\/webkul.com\/blog\/magento-development-08-filter-and-sorting\/\">Magento 2 Development 11: Filter and Sorting<\/a><\/p>\n\n\n\n<p>Previous Blog -&gt;&nbsp;<a href=\"https:\/\/webkul.com\/blog\/magento-development-06-form-validation-and-saving-data\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Development 09: Form Validation and Saving Data<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that we have saved the form data in Magento, let&#8217;s create a list where customers can view all of his\/her blogs. Redirection and Messages Earlier we displayed just a simple message saying &#8220;Saved&#8221; when the customer submitted the form. But it will be better to redirect to the list page after saving the data. <a href=\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":201,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9121],"tags":[2460,15568,15567],"class_list":["post-282419","post","type-post","status-publish","format-standard","hentry","category-magento-2","tag-magento-2","tag-odoo-bigcommerce","tag-odoo-bigcommerce-connector"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento 2: Collection List and Block - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento 2: Collection List and Block - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Now that we have saved the form data in Magento, let&#8217;s create a list where customers can view all of his\/her blogs. Redirection and Messages Earlier we displayed just a simple message saying &#8220;Saved&#8221; when the customer submitted the form. But it will be better to redirect to the list page after saving the data. [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-09T06:26:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-01T09:32:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-1200x194.png\" \/>\n<meta name=\"author\" content=\"Sanjay Chouhan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sanjay Chouhan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/\"},\"author\":{\"name\":\"Sanjay Chouhan\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462\"},\"headline\":\"Magento 2: Collection List and Block\",\"datePublished\":\"2021-02-09T06:26:17+00:00\",\"dateModified\":\"2024-08-01T09:32:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/\"},\"wordCount\":929,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-1200x194.png\",\"keywords\":[\"Magento 2\",\"odoo bigcommerce\",\"odoo bigcommerce connector\"],\"articleSection\":[\"Magento 2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/\",\"url\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/\",\"name\":\"Magento 2: Collection List and Block - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-1200x194.png\",\"datePublished\":\"2021-02-09T06:26:17+00:00\",\"dateModified\":\"2024-08-01T09:32:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1.png\",\"width\":1665,\"height\":269,\"caption\":\"2021-02-08_18-54-1\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento 2: Collection List and Block\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462\",\"name\":\"Sanjay Chouhan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Sanjay Chouhan\"},\"sameAs\":[\"https:\/\/www.instagram.com\/sanjaychouhansc\/\",\"https:\/\/in.linkedin.com\/in\/scchouhansanjay\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/sanjay-chouhan180\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento 2: Collection List and Block - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/","og_locale":"en_US","og_type":"article","og_title":"Magento 2: Collection List and Block - Webkul Blog","og_description":"Now that we have saved the form data in Magento, let&#8217;s create a list where customers can view all of his\/her blogs. Redirection and Messages Earlier we displayed just a simple message saying &#8220;Saved&#8221; when the customer submitted the form. But it will be better to redirect to the list page after saving the data. [...]","og_url":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2021-02-09T06:26:17+00:00","article_modified_time":"2024-08-01T09:32:03+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-1200x194.png","type":"","width":"","height":""}],"author":"Sanjay Chouhan","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Sanjay Chouhan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/"},"author":{"name":"Sanjay Chouhan","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462"},"headline":"Magento 2: Collection List and Block","datePublished":"2021-02-09T06:26:17+00:00","dateModified":"2024-08-01T09:32:03+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/"},"wordCount":929,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-1200x194.png","keywords":["Magento 2","odoo bigcommerce","odoo bigcommerce connector"],"articleSection":["Magento 2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/","url":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/","name":"Magento 2: Collection List and Block - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1-1200x194.png","datePublished":"2021-02-09T06:26:17+00:00","dateModified":"2024-08-01T09:32:03+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-08_18-54-1.png","width":1665,"height":269,"caption":"2021-02-08_18-54-1"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/magento-2-collection-list-block\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento 2: Collection List and Block"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462","name":"Sanjay Chouhan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Sanjay Chouhan"},"sameAs":["https:\/\/www.instagram.com\/sanjaychouhansc\/","https:\/\/in.linkedin.com\/in\/scchouhansanjay"],"url":"https:\/\/webkul.com\/blog\/author\/sanjay-chouhan180\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/282419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/201"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=282419"}],"version-history":[{"count":13,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/282419\/revisions"}],"predecessor-version":[{"id":455764,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/282419\/revisions\/455764"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=282419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=282419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=282419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}