Magento. Insert block into another without change template code

前端 未结 7 2021
耶瑟儿~
耶瑟儿~ 2021-02-06 01:36

I\'ve tried to find solution but with no results. My task is to write module. It should insert some html into existing block.

I noticed that when I used layout .xml file

7条回答
  •  耶瑟儿~
    2021-02-06 02:17

    There is a way to do this, although it is not an entirely elegant solution. It will work in most instances though and has proved helpful on occasion.

    Basically the idea is that you replace the block you want to render your block before/after in your layout XML, place that block as a child in your block and then render it's output before/after yours.

    So let's say you wanted to output a block before the totals block on the cart details page, you could do the following in your extension's layout.xml

    
        
            
                totalstotals
            
            totalsmyextension.block
        
    
    

    Then in your template.phtml file you would have:

    // Your template code
    // Render the totals block that you placed inside your block getChildHtml('totals'); ?>

    As I said, this won't fit every situation and it's not incredibly elegant, but it does work.

    Jon

提交回复
热议问题