Hot answers tagged

8

Create a Custom Module as Follows Vendor\ModuleName\registration.php <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Vendor_ModuleName', __DIR__ ); then Vendor\ModuleName\etc\module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/...


3

Update your XML with below content and check <block class="Vendor\Module\Block\Testing" name="customer.session.data" template="Vendor_Module::Test.phtml" before="-" cacheable="false" /> Or Add this line after referenceContainer tag <move element="customer.session.data" destination="sidebar.main" before="-" /> Or <referenceContainer name="...


3

Create app/code/Vendor/Module/view/frontend/layout/customer_account_index.xml <?xml version="1.0"?> <!-- /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ --> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:...


3

If you want to some specific product to a cms page. Then go to admin>Content>CMS page,Select your cms page,then open that cms page. Then go to the Content tab, click open widget icon. Please follow my step and check, please. I hope it will help you.


3

You can override this file vendor/magento/module-customer/view/frontend/templates/widget/gender.phtml in your custom theme here app/design/frontend/Vendor/Theme/Magento_Customer/templates/widget/gender.phtml Content for this file is.. <?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ /** @var ...


3

Check This Steps Step-1 : First you need to check your module is enable or not. Step-2 : You need to check are you working on right magento url or not. Step-3 : Check your Route name in routes.xml app\code\VendoreName\ModuleName\etc\frontend <?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...


2

Prefere setting template in layout, so it could be extended easily in other modules just using layout. If you have to set template depending on a condition, you could do it programmatically in block, just think of extensibility by using a public function (so it could be extended by plugin)


2

Supravat. I guess that you want to get Content from www.example.com/sales/order/view/order_id/{OrderId}/ when clicking into <h4> In that, I suggest is that implement ajaxContent of Collapsible widget that call www.example.com/sales/order/view/order_id/{OrderId}/ and get content of HTML out of Block sales.order.view. <block class="Magento\Sales\...


2

As always, it depends ;) I‘ve used the approach you describe, but I prefer to use method arguments instead, e.g. $viewModel->getSomeFoo($block->getProduct()); This decouples the view model from the block. However, if there are many public methods on the view model and many values from the block are required the setting the block on the view model ...


2

di.xml App/code/Vendor/Module/etc/frontend <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Vendor\Module\Model\ConfigProvider"> <arguments> <argument name="blockId" xsi:...


2

you can replace your code with this <?php namespace Butterfly\Emi\Block\Index; class Index extends \Magento\Framework\View\Element\Template { protected $_registry; protected $_categoryFactory; protected $_productPrice; public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Framework\...


2

Just Declare private $productPrice; And Use $this->productPrice Instead of $productPrice


2

You can find the Info.php on the below path. /vendor/magento/module-customer/Block/Account/Dashboard/Info.php You can override the block file in your custom module with the help of preference. Please visit this link for more information regarding the block overriding. And info.phtml under below path: /vendor/magento/module-customer/view/frontend/...


2

You can replace your XML file content with below content. <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="customer_account_navigation"> <block class="...


2

I found it, Basically there is a Block Magento\Sales\Block\Adminhtml\Order\Invoice\Totals.php which extends Magento\Sales\Block\Adminhtml\Totals, so I override this block Magento\Sales\Block\Adminhtml\Order\Invoice\Totals.php app/code/[Vendor]/[Module]/etc/adminhtml/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...


2

You might want to try calling the parent constructor to ensure all class dependencies are loaded as expected.


2

Please update your file with this content <?php namespace Test\Module\Block; use Magento\Framework\Registry; use \Magento\Framework\View\Element\Template; class StockLeft extends Template { private $registry; public function __construct( Template\Context $context, Registry $registry, array $data = []) { ...


2

You can use this in your Block file <?php namespace vendor\module\Block; use Magento\Customer\Model\Session; class Testing extends \Magento\Framework\View\Element\Template { public function __construct( Session $customerSession, \Magento\Framework\View\Element\Template\Context $context ) { parent::__construct($...


2

I have solved my problem using ajax post request on phtml file So I have created two phtml files and in my first phtml file which show the output data on page reload I have called the ajax post request to my custom controller <div id="customdata"></div> <?php $ajaxurl = $block->getAjaxUrl(); ?> <script type="text/x-magento-init"&...


2

You can use the url_rewrite table. Where you can search by request_path and use entity_id as your page Id. Or try this if works for you. protected $_page; public function __construct( ... \Magento\Cms\Model\Page $page, ... array $data = [] ) { parent::__construct($context, $data); ... $this->_page = $page; ... } /** ...


2

Add the below line in the same file in the <body> tag. <referenceBlock name="block_product_secondary_bottom" remove="true"/> or you can find the "block_product_secondary_bottom" block in Admin->Content->Blocks and Disable it. Flush the cache and check.


2

Using module you can add your block like this. Add in your layout file summary_index_index.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> ...


1

You are doing it correctly. You just need to change this: public function getCustomerName(){ $this->_customerSession->getCustomer()->getName(); } to: public function getCustomerName(){ return $this->_customerSession->getCustomer()->getName(); } You forgot return


1

1) app/code/[Vendor_Name]/[Namespace]/registration.php : <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, '[Vendor_Name]_[Namespace]', __DIR__ ); 2) app/code/[Vendor_Name]/[Namespace]/etc/module.xml : <?xml version="1.0"?> <config xmlns:xsi="http://www.w3....


1

You can set value in $filter object and access in your labels.phtml. Add this code in your layer/view.phtml file : <?= $filter->setData('custom_variable','custom_value'); <div class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->setCustomVariable($customData)->render($filter); ?>&...


1

You can replace this code Controller Search.php <?php namespace Vendor\SearchStores\Controller\Index; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\View\Result\PageFactory; use Magento\Framework\Registry; use Magento\Framework\Controller\Result\JsonFactory; //use Magento\Framework\Controller\...


1

You can check this file's Block here vendor/magento/module-customer/Block/Account/Dashboard/Info.php You can override this in your Custom module here app/code/Vendor/Module/Block/Account/Dashboard/Info.php Hope this will help you!


1

You just need a Block if you want to set a template filename dynamically or change something in Block functions like _prepareLayout, apart from that, if your template file is fixed, and you want to get data from some collection or model, you can use ViewModel. These are two great references about it: https://magento.stackexchange.com/a/277954/16416 https:/...


1

You can create new module and override that file otherwise you do that using custom theme as well. I'll show you here how can we override template file using custom module. Please create Vendor name directory first, and move into that and create another directory Module. Then you need to create registration.php file here. app/code/Vendor/Module/...


1

You can use Magento\Framework\View\Element\Template class to call phtml files {{block class="Magento\Framework\View\Element\Template" template="Vendor_Module::myfiles/myfile.phtml"}} To call advanced form use Magento\CatalogSearch\Block\Advanced\Form block class. {{block class="Magento\CatalogSearch\Block\Advanced\Form" name="block_name" template="...


Only top voted, non community-wiki answers of a minimum length are eligible