Reputation: 869
these days I am trying to improve my templates by using the Smarty template engine and its OOP template tag {block}
Its working pretty good, but I also noticed when I use {block} - tags the {include file="[...]" variableX="[..]"} breaks when I use nested variables.
PHP Fatal error: [...] variable template file names not allow within {block} tags
Some examples:
WORKING (without nested variable inside "param")
{block name=CONTENT}
{assign "extra" value="test"}
DropDown: {include "dropdown.html" param="product_name" items=DS::PRODUCTS()}
{/block}
NOT WORKING #1 (with nested variable using `` )
{block name=CONTENT}
{assign "extra" value="test"}
DropDown: {include "dropdown.html" param="product_name_`$extra`" items=DS::PRODUCTS()}
{/block}
NOT WORKING #2 (with nested variable using {} )
{block name=CONTENT}
{assign "extra" value="test"}
DropDown: {include "dropdown.html" param="product_name_{$extra}" items=DS::PRODUCTS()}
{/block}
When I am using {include} without {block} all examples are ok
Question: is there any other method to allow nested variables or is it a known issue?
Thank you in advance
Upvotes: 0
Views: 1265
Reputation: 367
Simple answer is - don not use such fancy techniques. If you really have no way around it, this likely means your design idea is flawed and needs to be rethought, or, in case of Smarty, you need a longer inheritance chain.
Check something like this.
Index template(index.tpl):
<html><head>
<title>{block 'page-title'}Silly title{/block}</title>
</head><body>{block 'page-content'}Silly content{/block}</body></html>
Single article content(index-content.tpl):
{extends 'index.tpl'}
{block 'page-title'}{$title|escape}{/block}
{block 'page-content'}{$content|render}{/block}
List/paged article content(list-content.tpl):
{extends 'list-index.tpl'}
{block 'page-title'}{$title|escape}{/block}
{block 'pager'}{somepaging}{/block}
{block 'list-content'}{somecontent}{/block}
The wrapper that the list is inherited from(list-index.tpl):
{extends 'index.tpl'}
{block 'page-content'}
{block 'pager'}[1] [2] [3]{/block}
{block 'list-content'}x{/block}
{block 'pager'}[1] [2] [3]{/block}
{/block}
When I'm rendering a simple article, I call index-content.tpl
. When I need a paged list, I call list-content.tpl
. I never call any of the base templates directly.
However, if your theme requere to enable or disable specific blocks of content on a page, you can always wrap selection in {if}
blocks. But honestly, I would urge you to reconsider your base design.
Upvotes: 1