Questions tagged [blocks]

denotes questions about the `Block` classes.

349 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
9
votes
0answers
800 views

Magento2: Conditionally replace block template and class the right way

This rather trivial requirement turns out be quite a pain for us in recent days, as we couldn't find a satisfying existing solution, yet. The Task We are trying to replace certain blocks with a ...
6
votes
2answers
682 views

Magento2 Extending Magento\Catalog\Block\Product\AbstractProduct Class

I wanted to add some extra custom methods to the block classes: Related Upsell Cross-sell Each of these extends the Magento\Catalog\Block\Product\AbstractProduct But using di.xml preference I was ...
5
votes
0answers
605 views

Template block has not been whitelisted error

I have a site with a CMS page using the 'core/template' block, and getting an error Security problem: core/template has not been whitelisted - even though the 'core/template' is clearly listed in the ...
4
votes
1answer
358 views

How to disable cache for perticular template file in magento 1.9?

We have used full page cache but some particular part of section not reflected. for example, we have a select city in the dropdown but not reflected. check my site- https://vidyutbazar.com/ A ...
4
votes
4answers
1k views

How to call module block after header?

I have a module layout file like below <default> <block name="ampromo_notification" type="ampromo/notification" template="amasty/ampromo/notification.phtml" before="-" /> <...
4
votes
1answer
2k views

magento2 -custom layout file not loading

i have followed the below link in order to get check if our custom layout xml file is loaded or not using the event: layout_generate_blocks_after In the log file i just get: 2016-06-29T11:07:40+00:...
4
votes
1answer
908 views

Render Javascript on customer_login event

I'm trying to render some javascript when the customer_login event fires by accessing a block on the layout from within the observer. I've successfully registered my observer to execute with the ...
4
votes
2answers
364 views

Magento getting store bestsellers: configurable products, only from current store

Magento getting store bestsellers: configurable products, only from current store We have tested some bestseller codes like from here and here and here. They all work fine if you only sell simple ...
3
votes
1answer
17 views

Magento2: Phtml file not visible on PDP

I have create a module which consists an extra button on the product description page . For this I have added a layout catalog_product_view.xml which is below. <?xml version="1.0"?> <page ...
3
votes
0answers
22 views

insert different block in the middle of block content

I have a phtml for a block like this : app/code/Vendor/Modul/view/frontend/templates/main.phtml <div class="business-container"> <nav class="mini-head"> </nav> <div class="...
3
votes
0answers
70 views

Block data are not shown in PHML magento 2

I am new to Magento 2 module development. I have a custom table sample_data(id,sample_text,sample_number) I want to fetch a listing of this custom table.But unfortunately when I type www....
3
votes
1answer
176 views

Can't access session into admin phtml file on Magento 2

I tried to set a session from a model file and access this on a phtml file like this and it's not working: namespace/vendor/Model/ProcessModel.php: protected $backendSession; public ...
3
votes
2answers
396 views

Override minicar sidebar price renderer

How can I override a sidebar.phtml from: module-weee/view/frontend/templates/checkout/cart/item/price/sidebar.phtml I have tried in the following ways: <referenceBlock name="checkout.cart.item....
3
votes
0answers
703 views

magento 2: \Magento\Theme\Block\Html\Topmenu $this->_menu

I am currently working on a custom block class that extends \Magento\Theme\Block\Html\Topmenu I have the following in my template file that uses my custom block class: <?php $menuTree1 = $block-...
3
votes
2answers
451 views

How to create a custom block from billing.phtml

I would like to add a new block in the customer registration, edit and billing forms. This block will contain a dropdown control where the customer can select if he wants to register as a company or ...
3
votes
2answers
1k views

Magento Container not working in custom layout

I have created a custom XML layout page that I will be using for my home page. Right now it is a clone of the normal 1column.xml layout, and I'm trying to add a container for an image slider. Here is ...
2
votes
0answers
26 views

ReferenceError: {var} is not defined

I have a problem with the frontend_model of the system.xml This is the system.xml <field id="words" translate="label" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="1"> ...
2
votes
0answers
32 views

Take value of a field in a block and place it in another field

I have a problem taking values from a system.xml field to show them in another field. This is the system.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
2
votes
0answers
22 views

Cache life time with varnish

Magento Magento\Framework\View\Element\AbstractBlock has method getCacheFiletime, it return lifetime of cache in seconds. How it will work with varnish?
2
votes
0answers
52 views

main.ERROR: Unable to resolve the source file for

if we do any modifications or if we add any image in tm_slider block and click on save button it is taking much time and getting 504 gateway time error and website is also not working 10 t0 15 mins at ...
2
votes
0answers
25 views

How to pass variable value from phtml JS to block.php?

I have a phtml (system.phtml) with <script> in it and a variable like console.log(data). <?php $checkcustomer = $block->Customerlogin(); ?> <script src="https://d3js.org/d3.v3.min....
2
votes
0answers
26 views

Magento sampledata sales banners

I have some questions regarding the sales banners on sample data Magento sites. For example the below banner In the blocks editor, the html code for this block looks like this: <a class="block-...
2
votes
2answers
52 views

Attempting To Override Pager - Type Error

Right now, I'm simply attempting to override the Pager class. Without changing anything within it, I've copied it into my module, and then specified the preference in the di: <config xmlns:xsi="...
2
votes
1answer
16 views

Magento 1.9 - exception 'Mage_Core_Exception' with message 'Invalid block type

Checking the log file of Magento 1.9, in two web site, I find this row: exception 'Mage_Core_Exception' with message 'Invalid block type: ES_Newssubscribers_Block_Newssubscribers How to remove ...
2
votes
4answers
257 views

Can I and should I call Block methods from its' View Model?

I have a template and should write some logic. I have made a view model and I'm calling it from a template. Should I call block methods from the view model? And if so, how can I do it?
2
votes
1answer
90 views

What is the use of getFormActionUrl()?

In Magento2.1.10 I am trying to make admin grid module and found below function in given path \app\code\xyz\Grid\Block\Adminhtml\Grid\addrow.php public function getFormActionUrl(){ if ($...
2
votes
0answers
31 views

Custom plugin files updated code is not showing in admin panel though cache is cleared

I have created a custom module. Controller files are working fine. I am trying to update my module MySQL version and adding new fields to the module in block folder files but they are not applying in ...
2
votes
0answers
27 views

Magento 2: How to remove Theme block in admin?

How to remove this block in back-end Categories > Design > Theme block New product > Schedule Design Update > New Theme block thank you!
2
votes
3answers
58 views

How can I print a attribute on phtml?

I want show relation information from the products under the descriptions, this information shouldn't be inside a tab but as if it were a dynamic block, for example, each product will have a different ...
2
votes
1answer
316 views

In which referenceContainer of product page we add block for custom rich snippets of current product?

I have to extend default rich snippets for products. For this I have my script in .phtml file as: <script type="application/ld+json"> { "@context": "http://schema.org/", "@type": "Product", <...
2
votes
0answers
115 views

Magento 2: How to validate cart price rule in product view?

I'm trying to show the price rules in the product view, but I can not find a way to validate if a product meets the rule... At the moment I just get all the rules. Block: class RuleDescription ...
2
votes
2answers
730 views

Rendering Html content for Header Block

I want to get my header part as html and I will use this in some other site with Api call. For that I am trying to render using the Magento\Theme\Block\Html\Header block. I am using the following code....
2
votes
0answers
54 views

Magento 2 :Header section modifications

I'm trying to understand how the entire header section is put together, and wanted to move some things around just to try to understand how Magento is putting everything together. How could I ...
2
votes
0answers
106 views

Magento 2 How can i Change Sortorder in fornted order_view.xml in order_total

I want to change sorting order in order_total block in frontend order view page. can any one tell me how i can change sorting order.
2
votes
1answer
544 views

Call block function from helper

I tried to call the block function from my custom module helper like this: $resultLayout = $this->_resultLayoutFactory->create(); $block = $resultLayout->getLayout()->getBlock('category....
2
votes
0answers
453 views

Magento 2: How to add Estimate Shipping and Tax in Minicart?

I want to add Estimate Shipping and Tax block on Minicart. It is possible to calculate tax and shipping from minicart block?
2
votes
1answer
332 views

CRUD logic in Controller or Block?

I have referred several blogs which explains CRUD functionality, some of the blogs write code like saving a model, in a Controller and some in a Block. Blogs CRUD functionality in Block : http://...
2
votes
2answers
688 views

Magento custom block rendered twice

i create a custom checkout block for checkout success page, but unfortunately the data printed twice first in the right div inside body, but the other printed after the footer, here's the ...
2
votes
0answers
423 views

Removing welcome message and breadcrumbs stops the title tag appearing on category page

I have the following lines of code in my Magento 2 template's Magento_Theme default.xml file: <referenceBlock name="header" remove="true"/> <referenceBlock name="breadcrumbs" remove="true"/&...
2
votes
0answers
66 views

Magento 2.1 : Cannot retrieve session variable

Im trying to save form token in session variable and get it back in the result page when the form is submitted. I created the following Session Model to handle sessions in my custom module: <?php ...
2
votes
1answer
173 views

Override block function

I want to filter wishlist product collection with a unique id. I have tried to override a method _createWishlistItemCollection located at the path /vendor/magento/module-wishlist/Block/AbstractBlock....
2
votes
2answers
88 views

Add review module to homepage

How do I add the review block that is visible on the category pages, to the home on the right side FROM THE BLOG is located. Do I need to just insert the block type in the cms page? I hoped just ...
2
votes
1answer
70 views

Overriding class Magento 2.1

I'm trying to inject \Magento\Framework\Filter\FilterManager $filterManager Object to be able to use truncate fucnction in list.phtml $this->_filter->truncate($string, ['length' => $...
2
votes
1answer
656 views

Block not showing after layout update

Considering this layout update XML: <?xml version="1.0"?> <layout version="0.0.1"> <checkout_cart_index> <reference name="methods"> <block type="...
2
votes
2answers
30 views

Magento block is not showing any content but it the block is being displayed

I am new to Magento development so forgive me if I am missing a step, I created a .phtml file and I have called it inside one of my cms pages by using the following {{block type="core/template" ...
2
votes
1answer
66 views

Update block arguemnts in xml file (Recommended way not working)

Magento 2.0.2 File :- vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml block :- <block class="Magento\Catalog\Block\Product\View\Attributes" name="product.attributes" ...
2
votes
1answer
285 views

Magento2: Block with arguments

I'm using Magestore's mega menu extension and using a plain content for rendering menu dropdowns. There, I want to use dynamic block's. I tried adding my dynamic block in xml layout file and its ...
2
votes
1answer
222 views

Help create a block to insert view.phtml

Help create a block to insert view.phtml. I have a layout file that outputs to buy in one click in the right column. I need to put this block alongside a buy button. <checkout_cart_index> &...
2
votes
1answer
454 views

Custom block not showing up on homepage

I just created my first own module. It is a Block that should be shown on the cms home page. Later on I want to change this into a custom navigation bar that is present on all pages of my shop but for ...
2
votes
3answers
777 views

Can't remove layout blocks. (Magento 2)

Information: I'm using Magento 2.1 on CentOS Linux, my theme is a child of the built-in Luma theme. When the theme I made is active, I want some blocks to be removed. Let's say I want to remove the ...