Questions tagged [blocks]

denotes questions about the `Block` classes.

Filter by
Sorted by
Tagged with
61 votes
6 answers
61k views

Magento 2: Changing a Block's Template

In Magento 1, as a module developer it's possible to change a block's template using layout XML code something like this <reference name="block_to_change"> <action method="setTemplate"&...
  • 43.8k
45 votes
3 answers
92k views

Remove block from layout XML in Magento 2

In Magento 1 I could remove a block added by a layout file by adding this in my layout-block <remove ="block_id_here" /> How can I do the same for Magento 2? As a practical exercise, let's say ...
  • 196k
38 votes
3 answers
20k views

Magento 2: template security: which method to use?

I'm aware Magento 2 has several methods available to secure the template: $block->escapeHtml() $block->escapeQuote() $block->escapeUrl() $block->escapeXssInUrl() But I'm wondering when ...
37 votes
4 answers
90k views

magento 2 how to call any block function in phtml

How can I call any block function in any phtml? For example if I want to call my custom block function in product list.phtml?
  • 856
34 votes
3 answers
34k views

Conditionally show/hide blocks in layout XML

How to conditionally add a block (depending on the configuration in the admin panel) in Magento's layout XML? We can check if config is true on actions. In the example below, if sample/config/...
  • 2,172
33 votes
3 answers
40k views

How can I disable cache for particular section or block

I have developed a top bar cart functionality for store front that displays latest three products added to the cart this works great when cache is disabled but when i enable the cache it showing weird ...
  • 1,525
26 votes
3 answers
26k views

Magento 2: get the current currency code

In Magento 1, you could retrieve the current currency code by doing: Mage::app()->getStore()->getCurrentCurrencyCode() I'm wondering what is the recommended way of doing it in Magento 2. In my ...
26 votes
3 answers
5k views

When to use 'name' and when to use 'as'

I've found that when trying to use the unsetChild method, sometimes I have to use the 'name' attribute and others 'as'. It seems that if a block is added normally, you use 'as' but if it is added to ...
  • 698
25 votes
4 answers
21k views

how to create multilingual static block

I need to create multilingual static block. So far I have created static block with id 'delivery_returns'. I'm calling it in catalog\product\view.phtml like this: $deliveryBlock = Mage::getModel('...
  • 1,049
24 votes
6 answers
53k views

How do I get the current product?

I'm trying to retrieve the current product's attributes in a block in Magento 2. I can get a product, like ID 1: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $...
24 votes
1 answer
13k views

DEBUG (7): Security problem: block_name has not been whitelisted. (Magento system.log)

In the system.log file of my Magento install I have the following error message DEBUG (7): Security problem: block_name has not been whitelisted. where block_name is the name of a block used in my ...
  • 3,602
23 votes
1 answer
21k views

Fatal Error Call to a member function dispatch() while call my Block in magento 2

This is my Block File: <?php namespace ChennaiBox\Mymail\Block\Mail; class MailContent extends \Magento\Framework\View\Element\Template { protected $_objectManager; protected $...
  • 3,500
21 votes
2 answers
7k views

Difference between <remove name=”" /> and <action method=”unsetChild”> in layout

What is the difference between <action method=”unsetChild”> and <remove name=""/>? Both functions are used to remove a block from the layout. Could someone explain with an example?
21 votes
1 answer
7k views

Block with Cachable=false not rendered on product view page

I am using magento2-1.0.0-beta4 I have copied the checkout.root block from app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml to the product page. Everything is working fine, ...
  • 14.2k
19 votes
3 answers
36k views

How to diagnose "Invalid block type .." error?

Not sure how to figure out this error, I've been googling for a week and I can't seem to find a solution. Any ideas? 2013-06-10T04:04:28+00:00 ERR (3): exception 'Mage_Core_Exception' with message '...
18 votes
4 answers
10k views

How to override Virtual Type class in Magento 2

How to override VirtualType block in Magento 2, I want to override following virtual type block with my own block, <virtualType name="Magento\CatalogSearch\Block\SearchResult\ListProduct" type="...
  • 2,204
18 votes
6 answers
24k views

Remove "product information, reviews, tags" block from product page

I am trying to remove a certain block from my product page in Magento, but can't seem to find where I should delete it. I think it's somewhere in the XML files, but since I'm not that good of a web-...
  • 339
16 votes
1 answer
10k views

DI & Extending a Block on Magento 2

I seem to be struggling to grasp Magento 2 dependency injection with blocks, every time I try to extend a block that isn't \Magento\Framework\View\Element\Template I end up with errors. I want to ...
  • 1,299
16 votes
1 answer
2k views

How can I include the checkout progress on the Paypal express review page?

Okay I've broken this down into steps and you can see where I am stuck: Step 1 - change column number The PayPal express review page (our page that PayPal sends the buyer back to in order to review ...
15 votes
5 answers
26k views

Magento 2 Get order total on success page?

I'm trying to get the order total on the success page on magento 2 , I have added this code <?php $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId()); $totall = $...
  • 1,447
15 votes
4 answers
14k views

Magento 2: Remove block depending on a config setting

I'm trying to remove a block from a certain page (be it frontend or backend) but only if a certain config flag is set to true. Let's take an example. I want to remove the block with the name dashboard ...
  • 196k
15 votes
3 answers
12k views

How to rewrite a class that has already been rewritten?

Update: I found that the class I actually need to rewrite is SMDesign_SMDZoom_Block_Product_View_Media and not SMDesign_ColorswatchProductView_Block_Product_View_Media like I originally thought. ...
  • 1,190
15 votes
3 answers
10k views

Magento 2 StoreManagerInterface already exists in context object in compilation

I am getting this error in my extension. PackageName\ModuleName\Block\Enhanced Incorrect dependency in class PackageName\ModuleName\Block\Enhanced in /var/www/html/app/code/...
  • 952
15 votes
2 answers
21k views

Load / Get a block outside of Magento routing for external use

I have an external webpage and I'm trying to pull the site header block from the Magento framework to use as a header in this external page. This is what I have so far: // initialize Magento $...
  • 1,190
14 votes
2 answers
59k views

Move blocks to other container how to

Being newby I look for a workaround to move Sign in and Store switcher from header.panel to header.container. I just tried this code but won't work <referenceContainer name="header.container"> ...
  • 887
14 votes
4 answers
23k views

Magento 2 How to Remove product information tabs

Please suggest how can we remove the "More Information" tabs from product details page See : http://awesomescreenshot.com/0f765e4128
14 votes
4 answers
14k views

setSaveParametersInSession() on a non-object

I'm getting setSaveParametersInSession() on a non-object It is on an admin module the path is Training/Distributor/Block/Adminhtml/ in this folder i have Distributor/Grid.php and Distributor.php ...
  • 1,707
14 votes
2 answers
25k views

Equivalent of the CMS Directive {{media url="..."}} in Normal Block Templates

What is the equivalent of {{media url="wysiwyg/image.jpg"}} which can be used in CMS pages if we want to use this in a normal .phtml file (of the type core/template)
  • 14.2k
14 votes
4 answers
30k views

How to override blocks in v2.1

I'm trying to override the Topmenu block in Magento 2.1 but can't find any guide to do so. Everything I've found on here and elsewhere either seems to apply only to version 2.0 which appears to use a ...
14 votes
4 answers
28k views

Pass data to getChildHtml() or call method on child block

I want to be able to pass data to the getChildHtml() call. The reason is, the output of the block is dependant upon a product type. So i want to pass the product to the getChildHtml so that it can ...
13 votes
3 answers
17k views

How do I override/rewrite a block class in Magento 1?

Note: This is intended as a canonical question that fully explains how block rewrites work and can be used as duplicate target for more specific "How do I override block X" or "Why does my rewrite not ...
13 votes
4 answers
21k views

Magento 2: How to add additional block on checkout page?

I would like to override the below file & display my custom block in the li. magento\vendor\magento\module-checkout\view\frontend\web\template\shipping.html <li id="shipping" class=&...
  • 9,553
13 votes
3 answers
10k views

Remove toolbar from product list via local.xml

I am used to using local.xml for my layout updates, however I cant seem to remove the toolbar from the product list block using either the remove or unsetChild methods. Can anyone say if this is ...
13 votes
4 answers
9k views

Possible to change block type in layout XML?

Is it possible to change a block type in layout XML? I know how to change template using setTemplate method, but I am trying to change a block's type. Is this possible?
12 votes
4 answers
22k views

Set and get block arguments programatically

In layout when I create a block I can set custom arguments, for example: <block class="Company\Module\Block\Hello" name="block_name" template="test.phtml"> <arguments> <...
  • 2,172
12 votes
1 answer
13k views

What is the difference between getChildHtml and getBlockHtml

Synopsis What is the difference between getChildHtml and getBlockHtml? How can I get the cms/block title in the template? I have essentially replaced the footer with my own footer and set my own <...
  • 1,736
12 votes
1 answer
18k views

Magento 2: How to add text within container via XML

I am attempting to render a single line of text prior to a Link list in the footer. Creating a template file to do this seems to be a waste of resources for this task. As I understood it, I could ...
12 votes
5 answers
10k views

Magento 2 Store switcher error in "section-config.js" Uncaught TypeError: Cannot read property '*' of undefined(…)

I'm implementing a custom store switcher in my custom theme. Block template is as follow: <?php if (count($block->getStores())>1): ?> <?php $id = $block->getIdModifier() ? '-' ....
  • 683
12 votes
3 answers
29k views

Invalid block type: [Namespace]\[Module]\Block\Timeline

I've been trying to add a block to the footer but so far it keeps returning Invalid block type: [Namespace]\[Module]\Block\Timeline The source of what I have so far can also be found here: https://...
  • 37.4k
12 votes
4 answers
8k views

Magento 2: How to change template of a block without "name"

I want to change to override a block's template with my custom template. But it does not have a "name", it only has a "as". The one I want to override is: <block class="Magento\Sales\Block\...
  • 2,154
12 votes
3 answers
1k views

Remove a block from layout without a name

I want to remove a block from the layout in magento 2 that is declared in a third party extension, but the block does not have a name. Can I do that? The block is declared like this <...
  • 196k
12 votes
3 answers
30k views

Magento new custom block module

I'm using Magento version 1.8.1.0. I'm trying to create a new custom block module, which I'll use for creating a new home page. Namespace: Crusader Module: CLHomePage Block Type: crusade home Class:...
12 votes
2 answers
2k views

Magento2: Conditionally replace block template and class the right way

This rather trivial requirement turns out to 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 ...
11 votes
2 answers
21k views

How to instantiate a block in magento2

Is there a simple way as in magento1 : $crumbs = Mage::app()->getLayout->getBlock('breadcrumbs');
  • 607
11 votes
2 answers
5k views

Magento 1 Widget setup in backend - how do I move upwards

I have a widget setup on all category pages via backend -> CMS - > Widgets Now when I use this method I select a block for category pages and the block shows up nicely. It is at the bottom of all ...
  • 5,332
11 votes
2 answers
4k views

How to get all children blocks in controller Magento 2?

I have to get all children block in controller using parent block name or layout Magento 2. Thanks in advanced.
11 votes
1 answer
2k views

Magento 2 - block name vs as name

I've been doing some work in Magento 2 and have been overwriting some modules i've installed ( on the frontend ). However today i've just come across something that I've not encountered before. The ...
  • 1,363
10 votes
6 answers
23k views

How to remove block from left or right panel in magento 2?

I want to remove compare product and wish list block from left panel. I don't want to change template. I am using 2columns-left. in magento 1.x, We uses like following in layout file. <...
10 votes
1 answer
16k views

Change page title in controler or block

I have found two ways for changing page title and I don't know which one I should use. 1. Override prepareLayout() in block protected function _prepareLayout() { $this->pageConfig->...
10 votes
4 answers
30k views

Passing variables to a child html block in Magento 2

At list.phtml, I am trying to get product object or product id for child template, which it comes from other module. How I can get product id at that phtml file? In magento 1.x it was possible via ...

1
2 3 4 5
36