Search code examples
phpsmarty

Dynamic insert the template to the base template


I want to dynamic insert the template to the base template:

I have three tpl, names test.tpl, test01.tpl, test02.tpl:

the code of test.tpl:

<html>
    <head>
        <title>{$title}</title>
    </head>

    {if $v eq 1}
        // there I want it to be test01.tpl, how to implements this?
    {elseif $v eq 2}
        // there I want it to be test02.tpl
    {/if}

    </body>
</html>

Solution

  • Check out this:

    <html>
        <head>
            <title>{$title}</title>
        </head>
        <body>
    
        {if $v eq 1}
            {include file='test01.tpl'}
        {elseif $v eq 2}
            {include file='test02.tpl'}
        {/if}
    
        </body>
    </html>
    

    {include} tags are used for including other templates in the current template.