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

problem with 2.6.1 parsing of {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 -> Bugs
View previous topic :: View next topic  
Author Message
brodie
Smarty n00b


Joined: 27 Jun 2003
Posts: 4

PostPosted: Tue Feb 10, 2004 9:39 am    Post subject: problem with 2.6.1 parsing of {if} Reply with quote

This is changed behaviour from 2.5.0 which has broken my application, can someone tell me if this is a bug or by design??

I have the following code in my template:
Code:
<td>{if $user.status == 'C'}{lang TXT_CURRENT}{else}{lang TXT_EXPIRED}{/if}</td>


The {lang XXX} tags are custom function tags that are replaced with localized text at template compile time. In short this works by having a compiler.lang.php function which converts "{lang XXX}" to "(LSEL.0XXX.LSEL)" which is later converted in postfilter.langselect.php to the actual text.

what I want is the behaviour of 2.5.0 where it turns into:
Code:
<td><?php if ($this->_tpl_vars['user']['status'] == 'C'): ?>Current<?php else: ?>Expired<?php endif; ?></td>


however what I'm getting with 2.6.1 is:
Code:
<td><?php if ($this->_tpl_vars['user']['status'] == 'C'):  (LSEL.0TXT_CURRENT.LSEL)  else:  (LSEL.0TXT_EXPIRED.LSEL)  endif; ?></td>


It seems that the php output of the {lang} custom function is being combined with the php output of the {if} builtin function in a single <?php ?> block. Is this a bug or a feature? To replicate the 2.5.0 behaviour I have to put spaces between the {if} and the {lang XXX} tags.

Regards,
Brodie
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Tue Feb 10, 2004 10:30 am    Post subject: Reply with quote

It's a feature.

unnecessary "?><?php"-sequences are stripped from the compiled template.

This is done before postfilters are applied. See Smarty_Compiler.class.php line 353 (Version 2.6.1 or CVS).
Back to top
View user's profile Send private message Send e-mail Visit poster's website
brodie
Smarty n00b


Joined: 27 Jun 2003
Posts: 4

PostPosted: Wed Feb 11, 2004 10:24 pm    Post subject: before post filters Reply with quote

Hi,

Thanks for the response. Was doing this prior to running the postfilters a conscious decision? Would it make a difference if this optimization occurred after the postfilters? (If not, then if it was moved then my problem would go away).

Regards,
Brodie
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Feb 12, 2004 12:21 pm    Post subject: Re: before post filters Reply with quote

brodie wrote:
Was doing this prior to running the postfilters a conscious decision?


I think it was a conscious decision, but I cannot remember what the reasons where.

I think it was placed before the post-filters, to avoid unforseen conflicts when postprocessing the output-filters output. I know, now you have a conflict because of unforseen pre-processing, though.

I suggest you put some unique delimiters around the return-values of your compiler-function and look for these delimiters in the postfilter. That should work safe with 2.5.0 (and before) and 2.6.0 (and after).
Back to top
View user's profile Send private message Send e-mail Visit poster's website
brodie
Smarty n00b


Joined: 27 Jun 2003
Posts: 4

PostPosted: Thu Feb 12, 2004 12:45 pm    Post subject: delimiters Reply with quote

Thanks for the comments. I actually do already have the delimiters. The problem is that I am trying to output plain text rather than PHP code. The compiled text looks something like:

<?php (PREFIX)CODE(SUFFIX) ?>

This is then supposed to be postprocessed into:

The text that CODE represented

Previously I was searching for and removing the "<?php (PREFIX)" and "(SUFFIX) ?>" strings, but now that there are times when the php source delimiters have already been removed, I find that my search is failing.

I've found a workaround which involves two passes over the text, but if there is no reason not to move the cleanup pass after the postfilters then that would be best for me.

Regards,
Brodie
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Feb 12, 2004 1:27 pm    Post subject: Re: delimiters Reply with quote

why do you insist on having your CODE inside php-tags if it isn't php-code?

I'd return something like
"?><?langselect CODE ?><?php" (because the return-value of the compiler-function is in php-context.

and look for
"<?langselect CODE ?>"
in the postfilter afterwards. no need for two passes.

the reason not to move the tag-stripping below the call to the postfilters is simple: in a few weeks somebody comes with the need to return his postfilter's results absolutely AS IS and requests to do the tag-stripping before the postfilters.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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 -> Bugs 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