Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty templates: How to change the order of blocks in child template?

I would like to change the order of parent blocks in a child templates while using the content of the parent blocks.

Example:

parent template:

{block outer}
    {block a} ... some long content ...{/block}
    {block b} ... some long content ...{/block}
    {block c} ... some long content ...{/block}
{/block}

child template:

{extends file="parent:parent.tpl"}
{block outer}
    {block c} reuse content of parent block "c" {/block}
    {block b} reuse content of parent block "b" {/block}
    {block a} reuse content of parent block "a" {/block}
{/block}

I tried using {$smarty.block.parent} inside block a, b and c:

{extends file="parent:parent.tpl"}
{block outer}
    {block c} {$smarty.block.parent} {/block}
    {block b} {$smarty.block.parent} {/block}
    {block a} {$smarty.block.parent} {/block}
{/block}

In this case {$smarty.block.parent} contains the content of the parent block "outer".

Is it possible to render the content of the inner blocks a, b and c inside the child template?

Scenario: The contents of blocks a, b and c is really complex and I want to avoid copying and pasting the whole contents from the parent.

like image 804
Leif Avatar asked Jul 14 '15 17:07

Leif


1 Answers

Though this is a old post this might be important for the future.
My best attempt at solving this issue is the following:

{extends file="parent:parent.tpl"}

{block a}
    {capture a}
        {$smarty.block.parent}
    {/capture}
{/block}

{block c}
    {capture c}
        {$smarty.block.parent}
    {/capture}
{/block}

{block b}
    {$smarty.capture.c}
    {$smarty.block.parent}
    {$smarty.capture.a}
{/block}
like image 80
AlexG Avatar answered Sep 28 '22 01:09

AlexG