Disclaimer: Magenticians does not necessarily agree with the views expressed in this guest post. They are presented to bring to light all diverse views in the Magento and general ecommerce community.
Many developers are now developing modules for Magento 2, but what if a module doesn’t exactly fulfill your requirements as you need it to? Imagine a scenario where you could understand the structure of a Magento 2 module somewhat better, to the point that you could change it to suit your requirements. Or even better, that you may develop your own module. In this tutorial, we are going to show you the structure of Magento 2 module and share with you the coding of “Twitter Feed” Magento 2 module. The goal of this module is to show Twitter feeds of a specific Twitter account. This tutorial will give you a basic idea about the structure and creation of Magento 2 modules.<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Magenticians_FeedModule" setup_version="1.0.0"></module> </config>
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magenticians_FeedModule', __DIR__ );
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd"> <router id="standard"> <route id="feedmodule" frontName="feedmodule"> <module name="Magenticians_FeedModule" /> </route> </router> </config>The router ID shows which router to use (same as Magento 1). The route ID indicates which node magento should look at to find the URL’s front Name and the frontName is the first part of the URL which should always be unique.
<?php namespace Magenticians\FeedModule\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { /** @var \Magento\Framework\View\Result\Page */ protected $resultPageFactory; /** * @param \Magento\Framework\App\Action\Context $context */ public function __construct(\Magento\Framework\App\Action\Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory) { $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } /** * Blog Index, shows a list of recent blog posts. * * @return \Magento\Framework\View\Result\PageFactory */ public function execute() { $resultPage = $this->resultPageFactory->create(); $resultPage->getConfig()->getTitle()->prepend(__('OnePage Twitter Feed')); return $resultPage; } }
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <block class="Magenticians\FeedModule\Block\FeedModule" name="magenticians_feedmodule" template="feedmodule.phtml"></block> </referenceContainer> </body> </page>
<?php namespace Magenticians\FeedModule\Block; class FeedModule extends \Magento\Framework\View\Element\Template { public function _prepareLayout() { return parent::_prepareLayout(); } }
<div style="display:table;height:100%;width:100%;text-align:center;"> <div style="display:table-cell;vertical-align:middle;"> <!-- PASTE YOUR WIDGET CODE HERE--> <a class="twitter-timeline" href="https://twitter.com/magenticians" data-widget-id="695189763914121216">Tweets by @Magenticians</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> <!-- PASTE YOUR WIDGET CODE HERE--> </div> </div>
Your greatest possible competitive advantage can be your clients and the interactions they have with… Read More
Digital marketing KPIs are measurable values that marketing teams use to track progress toward desired… Read More
In today's digital age, fraud poses a significant threat to businesses of all sizes. As… Read More
Financial crimes continue to evolve and proliferate in our increasingly digital, global economy. From complex… Read More
In the highly competitive modern workplace, trust, and employee loyalty are crucial factors for long-term… Read More
In the ever-evolving world of small business developing and implementing effective marketing strategies is critical to… Read More
View Comments
Thank's! :)
Your Welcome...!! :)
Your Welcome!
This is Gold!
Thanks :)
Thank you for sharing this wonderful post.
I want to recommend you Facebook and twitter integration Magento 2 extension which is easily integrate both social media platforms to your website.