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

variable in the 'include'->'file' attribute

 
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 -> Smarty Development
View previous topic :: View next topic  
Author Message
Tyz
Smarty n00b


Joined: 29 Nov 2004
Posts: 1
Location: Netherlands

PostPosted: Mon Nov 29, 2004 3:08 pm    Post subject: variable in the 'include'->'file' attribute Reply with quote

Hi,

This is wat i'm trying to do and will not work, so does anybody has a sollution or alternative?

I have 1 tpl file that is used for the main structure of the site, and I want to include all the element tpl's when there needed. Point is that the tpl it has to insert is dynamicly chosen.
In the main tpl I use the smarty 'include' function, my problem now is how to give the right tpl file with it.

{include file="theDynamicChosenTPL"}

Is there anyway to put a smarty variable in de file attribute?


grtz
Back to top
View user's profile Send private message MSN Messenger
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Nov 29, 2004 3:16 pm    Post subject: Reply with quote

{include file=$my_dynamic_tpl_file}
Back to top
View user's profile Send private message Visit poster's website
disoft
Smarty n00b


Joined: 09 Dec 2004
Posts: 4

PostPosted: Thu Dec 09, 2004 9:13 pm    Post subject: Reply with quote

Hi,

A related question to the above.

Is is possible to use a variable for part of the file name? What I'm trying to do is something like:

{include file="{$dirname}/filename.php"}

But I can't seem to get the syntax correct. Tried:

{include file=$dirname . "/filename.php"}
{include file="$dirname/filename.php"}

And a few others.


Best regards,
Gordon.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Dec 09, 2004 9:20 pm    Post subject: Reply with quote

{include} is for including other template files (and parsing them) from the template directory. To include arbitrary text files from the file system, use {fetch}. To include php scripts that are executed during inclusion, use {include_php}.
Back to top
View user's profile Send private message Visit poster's website
disoft
Smarty n00b


Joined: 09 Dec 2004
Posts: 4

PostPosted: Fri Dec 10, 2004 8:17 am    Post subject: Reply with quote

mohrt wrote:
{include} is for including other template files (and parsing them) from the template directory. To include arbitrary text files from the file system, use {fetch}. To include php scripts that are executed during inclusion, use {include_php}.


Okay, thanks for that, but it still doesn't allow me to use a variable in the call for part of the path. I presume that can't be done.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Dec 10, 2004 2:44 pm    Post subject: Reply with quote

Yes, this should work:

{include file="$foo/bar.tpl"}

assuming $foo is an assigned template var and this directory exists inside of your template directory.
Back to top
View user's profile Send private message 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 -> Smarty Development 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