|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ShaQ Smarty n00b
Joined: 27 Dec 2013 Posts: 1
|
Posted: Fri Dec 27, 2013 8:50 pm Post subject: Smarty 3.1.16 capture append foreach problem |
|
|
Hey Community,
i have the following code:
main.tpl:
Code: |
[{include file="test.tpl"}]
[{capture append="foo"}]
bar
[{/capture}]
[{foreach $foo as $bar}]
[{$bar}]
[{/foreach}]
|
test.tpl:
Code: |
[{capture append="foo"}]
foo
[{/capture}]
|
If i render the main.tpl, the output is: "bar".
But why?
Friendly Greez,
ShaQ |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Sat Dec 28, 2013 6:24 am Post subject: Re: Smarty 3.1.16 capture append foreach problem |
|
|
ShaQ wrote: | Hey Community,
i have the following code:
main.tpl:
Code: |
[{include file="test.tpl"}]
[{capture append="foo"}]
bar
[{/capture}]
[{foreach $foo as $bar}]
[{$bar}]
[{/foreach}]
|
test.tpl:
Code: |
[{capture append="foo"}]
foo
[{/capture}]
|
If i render the main.tpl, the output is: "bar".
But why?
Friendly Greez,
ShaQ |
Why are you expecting the output to be different?
From the include manual page:
All assigned variable values are restored after the scope of the included template is left. This means you can use all variables from the including template inside the included template. But changes to variables inside the included template are not visible inside the including template after the {include} statement.
Is that the part you needed clarification on? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Dec 28, 2013 1:39 pm Post subject: |
|
|
You can pass the variables from the subtemplate to the calling template like this
test.tpl:
Code: | [{capture append="foo"}]
foo
[{/capture}]
[{assign var='foo' value=$foo scope=parent}] |
|
|
Back to top |
|
|
|
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
|