Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3.1.21] Compiled template error when if/elif statements used in smarty function attributes #23

Closed
katiesandford opened this issue Apr 6, 2015 · 2 comments

Comments

@katiesandford
Copy link

I've found an interesting error in the compilation of templates in smarty 3.1.21

To reproduce use the following in a template file:

{capture assign="{if true}assign{/if}" name="{if true}name{elseif false}isnt-the-name{/if}"} <div>Do I appear?</div> {/capture} {$assign}

Expected behaviour:

We expect that the capture function should have the following attributes: name=name and assign=assign.
As the template includes {$assign}, we expect that:
<div>Do I appear?</div> should appear.

Actual behaviour:

Nothing will appear!
The compiled template code mixes up the order of the statements so that the 'if' in the assign attribute is only evaluated if the first if in the name attribute is false.
<?php ob_start();?><?php if (true){?><?php echo "name";?><?php }else{?><?php ob_start();?><?php if (true){?><?php echo "assign";?><?php }?><?php $_$ <div>Do I appear?</div> <?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);

The error in compilation occurs:

  • When we need to pass variables to a smarty function such as 'capture'. The error also occurs with other inbuilt smarty functions and custom functions.
  • When an if statement is followed by an elif statement. The if statement is evaluated in one 'attribute' and the elif statement is evaluate on another 'attribute'.
@uwetews
Copy link
Contributor

uwetews commented May 5, 2015

This bug is now fixed in dev-master.

The fix will later be included in 3.1.22

@uwetews uwetews closed this as completed May 5, 2015
@katiesandford
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants