View previous topic :: View next topic |
Author |
Message |
eposjk Smarty Rookie
Joined: 07 Oct 2009 Posts: 13
|
Posted: Wed Oct 07, 2009 7:50 pm Post subject: Smarty 3 doesn't like {if}{/capture}{capture}{/if} |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Oct 07, 2009 8:25 pm Post subject: |
|
|
Smarty3 did too stricly check block nesting on {capture} tags. The fix is in the SVN now. |
|
Back to top |
|
eposjk Smarty Rookie
Joined: 07 Oct 2009 Posts: 13
|
Posted: Wed Oct 07, 2009 9:20 pm Post subject: |
|
|
thanks - works fine! |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Wed Oct 07, 2009 11:00 pm Post subject: Re: Smarty 3 doesn't like {if}{/capture}{capture}{/if} |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Oct 08, 2009 7:21 am Post subject: |
|
|
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 |
|
eposjk Smarty Rookie
Joined: 07 Oct 2009 Posts: 13
|
Posted: Thu Oct 08, 2009 8:50 am Post subject: |
|
|
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 |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Thu Oct 08, 2009 10:35 am Post subject: Re: Smarty 3 doesn't like {if}{/capture}{capture}{/if} |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Oct 08, 2009 1:36 pm Post subject: |
|
|
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 |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Thu Oct 08, 2009 3:38 pm Post subject: |
|
|
good point |
|
Back to top |
|
|