Questions tagged [blocks]

denotes questions about the `Block` classes.

Filter by
Sorted by
Tagged with
49
votes
6answers
31k 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"&...
35
votes
3answers
50k views

Remove block from layout 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 ...
31
votes
3answers
38k 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?
31
votes
3answers
30k 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/...
31
votes
3answers
36k 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 ...
29
votes
2answers
6k 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 ...
26
votes
3answers
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 ...
23
votes
4answers
19k 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('...
22
votes
2answers
14k 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 ...
22
votes
1answer
12k 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 ...
21
votes
2answers
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
1answer
5k 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, ...
19
votes
2answers
30k 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
6answers
23k 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-...
17
votes
1answer
12k 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 $...
16
votes
1answer
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
3answers
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. ...
15
votes
3answers
8k 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/...
15
votes
1answer
8k 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 ...
15
votes
2answers
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 $...
14
votes
4answers
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 ...
14
votes
2answers
23k 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
votes
2answers
315 views

How to keep .phtml files lean and clean?

As its file extension suggests a .phtml file allows PHP code to be mixed with HTML. However, the fact that you can should not be seen as a license to go wild. Why do we still see so many .phtml ...
13
votes
4answers
8k 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 ...
13
votes
4answers
25k 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 ...
13
votes
3answers
9k 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
3answers
8k 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
3answers
14k 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 = $...
12
votes
3answers
4k 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="...
12
votes
4answers
24k 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 ...
12
votes
3answers
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: crusaderhome Class:...
11
votes
2answers
32k 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"> ...
11
votes
1answer
12k 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 <...
11
votes
4answers
5k 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() ? '-' ....
11
votes
2answers
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 ...
11
votes
3answers
749 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 <...
10
votes
2answers
13k views

How to instantiate a block in magento2

Is there a simple way as in magento1 : $crumbs = Mage::app()->getLayout->getBlock('breadcrumbs');
10
votes
3answers
13k 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 ...
10
votes
2answers
15k 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://...
10
votes
2answers
2k 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.
10
votes
0answers
818 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 ...
9
votes
4answers
11k 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
9
votes
1answer
10k 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 ...
9
votes
3answers
8k views

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

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

How to overwrite a template via module in Magento2

I am creating a module and want to overwrite the template app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit/options.phtml. Is this possible in a module (not a theme) ...
9
votes
4answers
5k 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\...
9
votes
1answer
3k views

How to add Block Specific JS (and CSS) - The _right_ way?

So I've spent literally hours on hours googling, reading, studying ect, but no one (not even Alan Storm!) has spelt this out to me. It seems the entire internet is interested in adding JS or CSS to a ...
9
votes
2answers
4k views

Adding a block to login onepage checkout

I try to add an additional login option during the checkout process. At the moment, you have the username/password way. I want to add a button image to login via an OAuth process (in my case Github). ...
9
votes
1answer
956 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 ...
8
votes
6answers
16k 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. <...