Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 3 doesn't like {if}{/capture}{capture}{/if}

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
eposjk
Smarty Rookie


Joined: 07 Oct 2009
Posts: 13

PostPosted: Wed Oct 07, 2009 7:50 pm    Post subject: Smarty 3 doesn't like {if}{/capture}{capture}{/if} Reply with quote

Smarty 3 complains about an unclosed if tag for

Code:
{capture name='abc'}
...
{if $a != $b}
  {/capture}
  {capture name='abc'}
{/if}
...
{/capture}


Smarty 2 accepts that without problems.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Oct 07, 2009 8:25 pm    Post subject: Reply with quote

Smarty3 did too stricly check block nesting on {capture} tags. The fix is in the SVN now.
Back to top
View user's profile Send private message
eposjk
Smarty Rookie


Joined: 07 Oct 2009
Posts: 13

PostPosted: Wed Oct 07, 2009 9:20 pm    Post subject: Reply with quote

thanks - works fine!
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Wed Oct 07, 2009 11:00 pm    Post subject: Re: Smarty 3 doesn't like {if}{/capture}{capture}{/if} Reply with quote

Just curious, how would the compiler work in cases like this:

Code:


{capture name='abc'}
...
{if $a == $b}
  {/capture}
{/if}

{if $c == $d}
  {capture name='abc'}
{/if}
...
{/capture}


Would that be a compile time error? Would it be a runtime error if $a==$b and $c!=$d? What should happen?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Oct 08, 2009 7:21 am    Post subject: Reply with quote

Good point. That was originally the reasion why I implemented strict block nesting checks also for capture.

The compiler can't detect cases like this. It can even more srew up if you nest capture blocks. Strange things could happen on run time depending on the "if" results.

So maybe we should rethink.
Smarty2 did not check this, but this should not be a reasionto make Smarty3 not safer.
Back to top
View user's profile Send private message
eposjk
Smarty Rookie


Joined: 07 Oct 2009
Posts: 13

PostPosted: Thu Oct 08, 2009 8:50 am    Post subject: Reply with quote

What about having two Smarty3 versions (or one with a mode switch):
  • one dropin-replacement version/mode for Smarty2 code
  • one strict version/mode for new code
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Thu Oct 08, 2009 10:35 am    Post subject: Re: Smarty 3 doesn't like {if}{/capture}{capture}{/if} Reply with quote

Code:

{capture name='abc'}
...
{if $a != $b}
  {/capture}
  {capture name='abc'}
{/if}
...
{/capture}


Allowing the above seems like it's just going to cause problems in the future. I would want the compiler to say that's an error.

As you suggested, perhaps there could be a Smarty 2 compatible version. Or, it perhaps the previous case could be solved by an append option in capture, or just appending yourself.

Code:

{capture name='abc'}
...
{/capture}

{if $a == $b}
   {assign var=append value=true}
{/if}

{capture name='abc' append=$append}
...
{/capture}



or

Code:

{capture name='abc'}
...

{/capture}
{capture name='xyz'}

...
{/capture}

{if $a == $b}
   {assign var=abc value="$abc$xyz"}
{else}
   {assign var=abc value=$xyz}
{/if}
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Oct 08, 2009 1:36 pm    Post subject: Reply with quote

This is no different than the issues you would have in PHP:

Code:
ob_start();

if($a != $b) {
  ob_end_clean();
  ob_start();
}

ob_end_clean();


Smarty should probably just handle it the same. ie. let the capture just run as-is, and it's the template developer's responsibility to handle the nesting issues.
Back to top
View user's profile Send private message Visit poster's website
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Thu Oct 08, 2009 3:38 pm    Post subject: Reply with quote

good point
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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