Template inheritance problems [3.1.11]

50 views
Skip to first unread message

Sergey Y.

unread,
Aug 12, 2012, 8:46:53 PM8/12/12
to smarty-d...@googlegroups.com
i have 4 files:
1. topic.prototpe.tpl -- consists topic structure with code/content in {block}'s
2. topic_link.tpl -- template of topic type: link
3. topic_quesion.tpl -- template of topic type: question
4. preview_topic.tpl -- universal preview template

problems:
A) [cache problem]
preview_topic.tpl starts with
{extends file="topic_{$oTopic->getType()}.tpl"}
when i changes topic type, display() sends to me result for previous topic type, but with content for new $oTopic

B) [chain inherit problem]
topic.prototpe.tpl consists code:
{block name="topic_body_wrap"}
...
{/bock}

topic_link.tpl extends topic.prototpe.tpl and consists code:
{block name="topic_body_wrap"}
..some code..
{$smarty.block.parent}
..some code..
{/bock}

preview_topic.tpl extends topic_{link|question}.tpl and consists code:
{block name="topic_body_wrap"}
..another code..
{$smarty.block.parent}
..another code..
{/bock}

i expects output from preview_topic.tpl:
..another code..
..some code..
...
..some code..
..another code..

but got something like that:
..another code..
..another code..
..some code..
...
..some code..

i tried to combine append/prepend attributes in {block}, but code positions unpredictable mixing too

uwe.tews

unread,
Aug 15, 2012, 8:41:53 AM8/15/12
to smarty-d...@googlegroups.com
A)
Template inheritance is as compile time process where parent and child templates are merged in a single compiled file.
For this reasion variable file names in {extends} can be used only if you use a compile_id which contains the variable part like
$smarty->compile_id = $oTopic->getType();  (see http://www.smarty.net/docs/en/variable.compile.id.tpl)

See also the note at http://www.smarty.net/docs/en/language.function.extends.tpl

Another solution is not to use the {extends} tags but the extends resource when calling display() see http://www.smarty.net/docs/en/resources.extends.tpl. Here you can use variable file names without defining a compile_id.


B)

I could not reproduce this problem.
I do get the expected result of:

..another code..
..some code..
...
..some code..
..another code..


Sergey Y.

unread,
Aug 21, 2012, 4:30:27 PM8/21/12
to smarty-d...@googlegroups.com
A)
thanx, second solution is more suitable in my case, i will try it.

B)
i've tried it on different servers (win32 and freebsd) with different versions of PHP and result was the same. may be it was side effect of problem "A".

среда, 15 августа 2012 г., 16:41:53 UTC+4 пользователь uwe.tews написал:
Reply all
Reply to author
Forward
0 new messages