3

I'm trying to add New Products to the CMS home page. In order to get pagination to work, I must add the toolbar and pager blocks as children of the product list block.

    <reference name="content">
        <block type="mywebsite_catalog/product_new" name="home_products" template="catalog/product/home.phtml">
            <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                <block type="page/html_pager" name="product_list_toolbar_pager"/>
                <action method="disableViewSwitcher"/>
                <action method="disableExpanded"/>
            </block>
        </block>
    </reference>

This is what I'm adding in the 'Design' tab of my CMS page, and it works, but the products are rendered after the CMS content - I need it between some of the CMS content.

As far as I know adding an 'inline' block using {{block type="..." template="..."}} is the only way to achieve that without editing the page's template. The problem for me with this is that it's not possible to nest inline blocks.

I've tried to programmatically add the child blocks, but was unsuccessful because it appears that inline blocks aren't actually part of any layout.

What's the best way of doing this?

1

Have you tried using {{layout handle=""}}?

Change your XML to the following:

<your_custom_handle>
    <block type="mywebsite_catalog/product_new" name="home_products" template="catalog/product/home.phtml">
        <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
            <block type="page/html_pager" name="product_list_toolbar_pager"/>
            <action method="disableViewSwitcher"/>
            <action method="disableExpanded"/>
        </block>
    </block>
</your_custom_handle>

Then use {{layout handle="your_custom_handle"}} in your CMS page or block.

  • Clever use of layout handles. – Rick Buczynski Dec 23 '14 at 5:06
0

You could treat the CMS page as a "container" for the content's layout:

<reference name="content">
    <block type="cms/block" name="cms_content_before">
        <action method="setBlockId">
            <id>some_block_id</id>
        </action>
    </block>
    <block type="mywebsite_catalog/product_new" name="home_products" template="catalog/product/home.phtml">
        <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
            <block type="page/html_pager" name="product_list_toolbar_pager"/>
            <action method="disableViewSwitcher"/>
            <action method="disableExpanded"/>
        </block>
    </block>
    <block type="cms/block" name="cms_content_after">
        <action method="setBlockId">
            <id>another_block_id</id>
        </action>
    </block>
</reference>

Where you break the content into 2 CMS blocks, inserting one above and one below the products block.

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.