|
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 |
Thomas Edwards Smarty n00b
Joined: 09 Dec 2009 Posts: 2
|
Posted: Wed Dec 09, 2009 1:04 pm Post subject: Trying to use a foreach within an include |
|
|
Hey guys,
Been using Smarty for a while now, really enjoying it – but I can't figure out how to get around this.
I have a bunch of "widgets" that I want to call. They're kept in a folder.
Code: | {foreach from=$widgets item=w}
{include file="widgets/$w.widget_id"}
{/foreach} |
However, as you might have guessed, that produces an error
Severity: User Warning
Message: Smarty error: unable to read resource: "widgets/Array.widget_id"
Filename: libs/Smarty.class.php
Anybody know a better way of doing this? Or indeed, the solution? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Dec 09, 2009 5:16 pm Post subject: |
|
|
You must use backticks.
Code: | {foreach from=$widgets item=w}
{include file="widgets/`$w.widget_id`"}
{/foreach} |
See documentation for variables in double quoted strings. |
|
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
|