View previous topic :: View next topic |
Author |
Message |
emptykid Smarty Rookie
Joined: 08 Sep 2010 Posts: 9 Location: Beijing, China
|
Posted: Wed Sep 08, 2010 10:46 am Post subject: A bug occurs when {include} meet {extends} |
|
|
Codes as below
frame.tpl:
{block name="b"} {/block}
page1.tpl:
{extends file="frame.tpl"}
{block name="b"}
This is page1
{/block}
page2.tpl:
{extends file="frame.tpl"}
{block name="b"}
This is page2
{/block}
page.tpl:
{include file="page1.html"}
{include file="page2.html"}
when display("page.tpl")
The result is:
This is page1
This is page1
check the template_c sources, the page2.tpl content is the same with page1.tpl
This problem make me sad when coding... And I don't know what to do. I need that logic... |
|
Back to top |
|
rocky Smarty Regular
Joined: 08 Feb 2010 Posts: 35
|
Posted: Wed Sep 08, 2010 10:58 am Post subject: |
|
|
that's right. but that are not a bug. smarty compile a template only once.
i haved found 2 resolution for that:
example 1:
Code: | $this->template->compile_id = 'page1';
$this->template->display('page1.tpl');
$this->template->compile_id = 'page2';
$this->template->display('page2.tpl'); |
example 2:
Code: | frame.tpl:
{block name="b"} {/block}
frame1.tpl:
{extends file="frame.tpl"}
frame2.tpl:
{extends file="frame.tpl"}
page1.tpl:
{extends file="frame1.tpl"}
{block name="b"}
This is page1
{/block}
page2.tpl:
{extends file="frame2.tpl"}
{block name="b"}
This is page2
{/block}
page.tpl:
{include file="page1.html"}
{include file="page2.html"} |
|
|
Back to top |
|
emptykid Smarty Rookie
Joined: 08 Sep 2010 Posts: 9 Location: Beijing, China
|
Posted: Wed Sep 08, 2010 11:09 am Post subject: |
|
|
To rocky:
thx for you answer!
I am not alowed to modify the php script
So I test example 2, which works not well...
I test the code you post and the result is the same... |
|
Back to top |
|
rocky Smarty Regular
Joined: 08 Feb 2010 Posts: 35
|
Posted: Wed Sep 08, 2010 12:21 pm Post subject: |
|
|
oh sorry.
in which template are the block "b"?
this problem exits only when the block are in a included template.
the resolution are the extending the included template.
Code: | include.tpl:
{block name="b"} {/block}
frame.tpl:
{block name="i"}{include file='include.tpl'}{/block}
include1.tpl:
{extends file="include.tpl"}
include2.tpl:
{extends file="include.tpl"}
page1.tpl:
{extends file="frame.tpl"}
{block name="i"}{include file='include1.tpl'}{/block}
{block name="b"}
This is page1
{/block}
page2.tpl:
{extends file="frame.tpl"}
{block name="i"}{include file='include2.tpl'}{/block}
{block name="b"}
This is page2
{/block}
page.tpl:
{include file="page1.html"}
{include file="page2.html"} |
|
|
Back to top |
|
emptykid Smarty Rookie
Joined: 08 Sep 2010 Posts: 9 Location: Beijing, China
|
Posted: Wed Sep 08, 2010 1:40 pm Post subject: |
|
|
To rocky:
I am so sorry to tell you that the code you post second time doesn't work well either...
The result turn out the same...
This is page1
This is page1
I can hardly accept that case is not a bug...
I just want a simple function
I do the right way to get the right thing, but the engine give me a wrong one...
And thank you again! so much! |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Sep 08, 2010 3:12 pm Post subject: |
|
|
The current implementation of template inheritance does not allow parallel extends chains starting in subtemplates. (I did not think about it)
I will try to modify the code for this during the next couple of days. |
|
Back to top |
|
emptykid Smarty Rookie
Joined: 08 Sep 2010 Posts: 9 Location: Beijing, China
|
Posted: Wed Sep 08, 2010 3:24 pm Post subject: |
|
|
U.Tews wrote: | The current implementation of template inheritance does not allow parallel extends chains starting in subtemplates. (I did not think about it)
I will try to modify the code for this during the next couple of days. |
Ala! Thank you for your answer, You give me the hope!
But do you have any other way to resolve that problem??
I just want that logic work, no matter which way... |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Sep 08, 2010 5:46 pm Post subject: |
|
|
The update is now in the SVN. |
|
Back to top |
|
|