Calling for template blocks within the same template file
| From: | news.php.net | Date: | Tue, 19 Nov 2002 09:41:47 +0000 |
| Subject: | Calling for template blocks within the same template file | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-6469@lists.php.net to get a copy of this message | ||
Hi people.
I used XSLT transformations before, but now I decided to use Smarty, as it
requires no server installation. I liked Smarty from the first sight, but
still I met a problem, which I do not know how to solve.
I use this approach: depending on a request, my code generates different
arrays of data (like xml data using xslt), and assigns them to Smarty, then
calls ->display("template.tpl"). Ok, now I want that "template.tpl" would
have template not only for current query (current generated and assigned
array), but also for all other cases (generated arrays), and I could choose
the needed template block within that .tpl file for example using
{if}...{/if} structure. That chooseing would on a template level, and my
code would not depend on that.
But I also need some common template blocks, which would be called
explicitely by other blocks within the same template.tpl. (like
<xslt:call-template> in xslt).
For example:
{*template.tpl*}
{* NEWS_BLOCK template block for news*}
{if $query eq "show_news"}
<H1>NEWS</H1>
{* HERE I would like to call for the COMMON_BLOCK template from below
for showing a list of this items *}
{/if}
{*end of NEWS_BLOCK*}
{*ANNOUNCES_BLOCK template block for announces*}
{if $query eq "show_announces"}
<H1>NEWS</H1>
{* HERE I would like to call for the COMMON_BLOCK template from below for
showing a list of this items *}
{/if}
{*end of ANNOUNCES_BLOCK *}
{* COMMON_BLOCK, template block, common for showing news, announces and so
on ..., WHICH I WOULD LIKE TO CALL FROM THE ONES ABOVE (NEWS_BLOCK and
ANNOUNCES_BLOCK), but it SHOULDN'T BE PROCESSED, while I do not need it! *}
<TABLE>
{foreach from=$data item=data_item}
<TR> <TD>{$data_item.subject}</TD>...
{/foreach}
</TABLE>
{* end of template block, common for showing news, announces and so on ...
*}
{*end of template.tpl*}
Naturally, the COMMON_BLOCK part should be processed by smarty, intil I call
it explicitely, when needed.
SO, the problem IS: is there any possibility to do that ???(without putting
that COMMON_BLOCK to different file, as I need to have only one templete
file due special reasons.)
Thanks in advance,
Mark D.