Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [blocks]

denotes questions about the `Block` classes.

46
votes
6answers
28k 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"&...
30
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 ...
35
votes
3answers
46k 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 ...
12
votes
3answers
13k 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
4answers
24k 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 ...
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 '...
20
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, ...
10
votes
3answers
12k 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 ...
4
votes
2answers
10k views

How to override core catalog block product list?

I am trying to override core/catalog/block/product/List.php with following Ref:http://www.magentocommerce.com/boards/viewthread/14692/ file: Ziva/Customcatalog/etc/config.xml <config> <...
31
votes
3answers
29k 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/...
27
votes
2answers
5k 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 ...
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 ...
2
votes
2answers
4k views

Overriding Block in Magento 2

I'm playing overriding the blocks in magento 2, extended block constructor is calling but inside method is not working? my code is di.xml <?xml version="1.0"?> <config xmlns:xsi="http://...
7
votes
2answers
1k views

Re-add left block after it's been removed

Running Magento 1.9 CE. I am trying to re-add a left block after is has been removed in base. base/default/layout/storelocator.xml: <dealers_index_index translate="label"> <update ...
9
votes
1answer
9k 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 ...
3
votes
2answers
6k views

Customise a custom product attribute input renderer in Magento 2 the right way

I'm facing to a very ridiculous trouble, I added a custom product attribute with source model, backend model as a select box. Everything works fine (my custom attribute will get the values from a ...
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 $...
25
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 ...
9
votes
2answers
29k 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"> ...
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('...
4
votes
2answers
358 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 ...
4
votes
2answers
13k views

Magento 2: How to call custom phtml file in another phtml file?

I'm trying to output custom phtml content of Lapisbard_General::customer_account.phtml in Magento_directory::currency.phtml If I'm using below code, it works fine. echo $this->getLayout()->...
3
votes
1answer
9k views

Magento 2: How to move Details tab to product info column?

In Magento 2, the Blank theme displays the Details tabs below product images. How to move this block to the product info column (right side of the page, under Add to cart button)?
2
votes
1answer
2k views

How to use setTemplate() in Custom modules _construct() magento2

How to achieve the setTemplate() in the custom modules constructor? protected function _construct() { $this->setTemplate('Myfolder/filter.phtml'); } protected function _toHtml() { return ...
0
votes
2answers
2k views

Layout XML block rendered twice in Magento skin

I'm having a bit of trouble with a custom layout block which I'm trying to add to the head.phtml file of my theme. Basically, I'm trying to add extra favicon definitions to the header of my document. ...
12
votes
3answers
7k 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 ...
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:...
14
votes
4answers
13k 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 ...
4
votes
2answers
17k views

How To Create a Custom Block in Custom Module?

I have followed a tutorial to create the block. All codes are in here http://www.pierrefay.com/magento-create-block-44 but I cant seem to connect to the template file, no matter where i put it. i ...
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\...
4
votes
4answers
14k views

Magento 2: how to get Model in Block

I want to use an instance of a Model into a Block. in Magento 1 they uses: $exple = Mage::getModel('exple/standard'); How can I do this with Magento 2?
3
votes
1answer
8k views

Add Javascript File To Head For Create Block

I need to create a block programatically (for various reasons): $myblock = Mage::app()->getLayout()->createBlock('namespace_module/path', 'my_block', $params); This works fine, but the ...
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="...
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 ...
8
votes
1answer
13k views

Link for action column in custom grid

I have a custom grid which resembles the Manage Products grid in Catalog Menu. I need to get the corresponding action link to each entity item. How do i do that? My custom grid is declared in the ...
5
votes
1answer
788 views

Difference Between $block and $this magento 2

I have block Class Name NameSpace1\Test\Block\Test with method getTest() namespace NameSpace1\Test\Block; class Test extends \Magento\Framework\View\Element\Template { public function getTest(){ ...
4
votes
3answers
1k views

Category Product List : add a custom view mode via observer

So I'm trying to accomplish the following: I want to add a third view mode to the product listing (I called it "gridx5") using event observers. I originally did it via Blocks rewrites and it was ...
4
votes
1answer
4k views

Display more than one category in the same CMS Page

I need to develop a landing page with products from different categories. Something like: Banner Products from category 1 Banner Products from category 2 I'm trying to do it like ...
3
votes
1answer
2k views

Trouble adding JS to before body end without modifying Magento theme

I need to add javascript to just before the closing body tag. Move all Javascript includes to before </body> has is a solution but it seems to me that overriding page/html/footer.phtml will ...
3
votes
2answers
6k views

Add block to category page

I want to add a custom block to the category pages and not care if the the category is anchor or not or if it has children or not. I want to add that block at the bottom of the page after the product ...
2
votes
1answer
5k views

Magento 2 - Show custom Block on Cart Page

Namespacee/Modulename/Block/Productpoint.php <?php namespace Namespace\Modulename\Block; class Productpoint extends \Magento\Framework\View\Element\Template { public function __construct( ...
1
vote
1answer
4k views

overwriting adminhtml block from another extension doesn't work

I'm trying to find a solution since a couple hours now. Unfortunately without any luck, so I need to ask you for help. I'm trying to add a download button to a grid which will be provided by an ...
1
vote
1answer
458 views

Editing an Existing Theme - Locating the XML

Sorry for the beginner question but I'm completely stuck, otherwise I wouldn't ask. I'm determined to learn Magento correctly and need pointing in the right direction before I can continue. I'm ...
4
votes
4answers
3k views

CMS Block Cache issue with included dynamic template

I've seen lots of issues with CMS block caching in Magento 1.9.2.0 and have an issue where I've created a static block that loads the current category ID and then displays variables that have a ...
3
votes
1answer
654 views

remove crumb from breadcrumbs

is there any way remove specific crumb from breadcrumbs ? we can add crumb method addCrumb from Block Class Mage_Page_Block_Html_Breadcrumbs but I didn't find any method to remove crumbs like ...
3
votes
1answer
3k views

How do add css, js in customview.phtml in view magento2?

I have custom view.phtml. I Want add my.css and my.js in <head></head> 2 file in app\code\Test\New\view\frontend\web\css. How do it?
2
votes
1answer
975 views

need to add custom template file inside form container magento admin

What i have tried is the following. I have a class which extends Mage_Adminhtml_Block_Widget_Form. Inside that i have the _prepareLayout function. Now i have set a block inside that function like ...
2
votes
1answer
540 views

Add block in left column if it was removed in the default file [duplicate]

I have a 2 columns - left layout for the checkout_cart_index. In the checkout.xml file, the left column is removed: <checkout_cart_index translate="label"> <remove name="left"/> &...
1
vote
1answer
467 views

Overwrite template without the “name” attribute

How can I overwrite the template of something like select.phtml <block class="Magento\Catalog\Block\Product\View\Options" name="product.info.options" as="product_options" template="...