Smarty, use template functions from included template

658 views Asked by At

I have a Smarty (version 3.1.21) template like this:

<div>
    {include file='includes/test.tpl'}
    {pagebuilder data=$data.top_description}
</div>

includes/test.tpl content is:

{function name=pagebuilder}
    {foreach $data as $row}
       ...
    {/foreach}
{/function}

Error message is:

Syntax error in template "/home/master/projet/public/templates/controllers/pagebuilder-preview.tpl" on line 29 "{pagebuilder data=$data.Content}" unknown tag "pagebuilder"

How to ommit unknown tag error after include file and properly use function from included template?

2

There are 2 answers

1
Lukas Liesis On

try using assign:

{include file='includes/test.tpl' assign=pagebuilder}
0
userlond On

External defined template functions must be called with the {call} tag. So your base template should be rewrited into:

<div>
    {include file='includes/test.tpl'}
    # {pagebuilder data=$data.top_description} 
    {call name=pagebuilder data=$data.top_description}
</div>