Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

A bug occurs when {include} meet {extends}

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
emptykid
Smarty Rookie


Joined: 08 Sep 2010
Posts: 9
Location: Beijing, China

PostPosted: Wed Sep 08, 2010 10:46 am    Post subject: A bug occurs when {include} meet {extends} Reply with quote

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
View user's profile Send private message
rocky
Smarty Regular


Joined: 08 Feb 2010
Posts: 35

PostPosted: Wed Sep 08, 2010 10:58 am    Post subject: Reply with quote

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
View user's profile Send private message
emptykid
Smarty Rookie


Joined: 08 Sep 2010
Posts: 9
Location: Beijing, China

PostPosted: Wed Sep 08, 2010 11:09 am    Post subject: Reply with quote

To rocky:

thx for you answer!

I am not alowed to modify the php script

So I test example 2, which works not well... Sad

I test the code you post and the result is the same...
Back to top
View user's profile Send private message
rocky
Smarty Regular


Joined: 08 Feb 2010
Posts: 35

PostPosted: Wed Sep 08, 2010 12:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
emptykid
Smarty Rookie


Joined: 08 Sep 2010
Posts: 9
Location: Beijing, China

PostPosted: Wed Sep 08, 2010 1:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5067
Location: Hamburg / Germany

PostPosted: Wed Sep 08, 2010 3:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
emptykid
Smarty Rookie


Joined: 08 Sep 2010
Posts: 9
Location: Beijing, China

PostPosted: Wed Sep 08, 2010 3:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5067
Location: Hamburg / Germany

PostPosted: Wed Sep 08, 2010 5:46 pm    Post subject: Reply with quote

The update is now in the SVN.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP