0

I created a new template file, where I placed some custom code, that I want to load inside a page.

I created a CMS page where I load the template file by using:

{{block type="core/template" template="/aw_blog/share.phtml"}}

I need to use the same php code as the default template file, so I need to define the template by: <?php $post = $this->getPost();?>

The default template file is defined inside the XML file like:

    <reference name="content">
        <block type="blog/post" name="post" template="aw_blog/post.phtml">
            <block type="blog/product_toolbar" name="aw_blog_list_toolbar" template="aw_blog/toolbar.phtml">
                <block type="blog/html_pager" name="product_list_toolbar_pager"/>
            </block>
        </block>
    </reference>

So I edit the XMl file:

    <reference name="content">
        <block type="blog/post" name="post" template="aw_blog/post.phtml">
            <block type="blog/product_toolbar" name="aw_blog_list_toolbar" template="aw_blog/toolbar.phtml">
                <block type="blog/html_pager" name="product_list_toolbar_pager"/>
            </block>
        </block>
        <block type="blog/post" name="post" template="aw_blog/share.phtml">
            <block type="blog/product_toolbar" name="aw_blog_list_toolbar" template="aw_blog/toolbar.phtml">
                <block type="blog/html_pager" name="product_list_toolbar_pager"/>
            </block>
        </block>
    </reference>

But that does not work, because that breaks down the page. It does not load the default content anymore.

What am I missing?

2

Try to use same block type in directive. Instead:

{{block type="core/template" template="/aw_blog/share.phtml"}}

use:

{{block type="blog/post" template="/aw_blog/share.phtml"}}

If you need to customize block behavior, then make a custom module with a block extending from blog one and use it in layout and template.

You will have to add the block type to the block whitelist that has been introduced in Magento 1.9.2.2 (and with a security patch for older versions), otherwise it will not be displayed. See APPSEC-1057 How to add variables or blocks to the white list tables

  • Thanks! I tried that, but in that case the total block is not displayed inside the page. – JGeer Feb 18 '16 at 8:23
  • Is the first slash needed ? Never seen that before, it's usually just aw_blog/share.phtml – Raphael at Digital Pianism Feb 18 '16 at 9:41
  • The slash is unnecessary but should not do harm. The problem is block whitelisting, see updated answer. – Fabian Schmengler Feb 19 '16 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.