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

Trying to use a foreach within an include

 
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 -> General
View previous topic :: View next topic  
Author Message
Thomas Edwards
Smarty n00b


Joined: 09 Dec 2009
Posts: 2

PostPosted: Wed Dec 09, 2009 1:04 pm    Post subject: Trying to use a foreach within an include Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Dec 09, 2009 5:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
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 -> General 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