Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Including Other TPL Files
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Thu Oct 16, 2003 8:37 pm    Post subject: Including Other TPL Files Reply with quote

hello,

the way i have my site setup is like so

/
/smarty/
/themes/
/themes/default/
index.php

now in my themes/default/ are all my TPL files, they seem to work, however when i use an include in my header.tpl file to include navmenu.tpl which are in the same directory, it isn't called or included
here is what i am using

{include file="$theme_dir/navmenu.tpl"}

i got that from the smarty site.

Joe


Last edited by idle0ne on Thu Oct 16, 2003 8:45 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website AIM Address
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Thu Oct 16, 2003 8:44 pm    Post subject: Reply with quote

i checked the compiled template and here is what smarty is using for the include. I am not sure if this is correct or not....



<?php
$_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include($this->_tpl_vars['theme_dir']."/navmenu.tpl", array());
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
?>
Back to top
View user's profile Send private message Visit poster's website AIM Address
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Thu Oct 16, 2003 8:48 pm    Post subject: Reply with quote

i have even attempted this

<!-- #include file="{$theme_dir}/navmenu.tpl" -->

and it seems smarty won't allow that type of include and just prints it as a comment to the browser Sad
Back to top
View user's profile Send private message Visit poster's website AIM Address
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Thu Oct 16, 2003 9:47 pm    Post subject: Reply with quote

anyone have any ideas?
Back to top
View user's profile Send private message Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Oct 16, 2003 9:49 pm    Post subject: Reply with quote

Include works by starting to scan for files in your templates_dir. So to inlclude a template you simply say {include file="template.tpl"}. Now, say you want to include a template from a subdir, you type {include file="subdir/subtemplate.tpl"}.

In your example, $theme_dir must be a dir that is under templates_dir, eg: $theme_dir = "subdir".

On the otherhand, if you want to use an absolute path, then you must prefix the path with the file resource: {include file="file:/path/to/template/...."}

HTH
Back to top
View user's profile Send private message
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Thu Oct 16, 2003 10:06 pm    Post subject: Reply with quote

right now the way they are being called is like so

$theme_dir = themes/default/

so it is calling like this when evaluated

{include file="themes/default/navmenu.tpl"}

but for some odd reason it's not including the file Sad
Back to top
View user's profile Send private message Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Oct 16, 2003 10:20 pm    Post subject: Reply with quote

what IS Smarty doing? Do you get an error? Make sure that dbugging is turned on and that error reporting is at E_ALL.

EDIT: According to your first post, themes/ is not a subdir of your template directory.
Back to top
View user's profile Send private message
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Thu Oct 16, 2003 10:27 pm    Post subject: Reply with quote

is it searching /smarty/templates/

??

if so how can i change that to make it search /themes/default/
Back to top
View user's profile Send private message Visit poster's website AIM Address
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Thu Oct 16, 2003 10:27 pm    Post subject: Reply with quote

wait i already have that set Smile

$this->_smarty->template_dir = $site->_settings->theme;

$site->_settings->theme = themes/default/
Back to top
View user's profile Send private message Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Oct 16, 2003 10:41 pm    Post subject: Reply with quote

if themes/default/ is your template dir, then smarty won't find $theme_dir/template.tpl when $theme_dir = 'themes/default' UNLESS you have your template directory (themes/default/) contains a directory structure that includes "themes/default/" (ie. "themes/default/themes/default/template.tpl" must exist).

Phew. I hope that makes sense!
Back to top
View user's profile Send private message
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Thu Oct 16, 2003 10:55 pm    Post subject: Reply with quote

i qm confused lol here's my dir structure

base/
base/theme/
base/theme/default/
base/smarty/

and i have smarty's template var pointing to base/theme/default, do i not???

i am confused as to why it's not working hehe, do i need to specify the full path and not a reletive path?
Back to top
View user's profile Send private message Visit poster's website AIM Address
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Oct 16, 2003 10:59 pm    Post subject: Reply with quote

idle0ne wrote:
i qm confused lol here's my dir structure

base/
base/theme/
base/theme/default/
base/smarty/

and i have smarty's template var pointing to base/theme/default, do i not???


The way I read it, I think you want to point templates_dir to 'base/theme' and then do your includes using $theme_dir = 'default' (or whatever the appropriate theme is). That way it will resolve to default/template.tpl which will resolve to $templates_dir.'default/template.tpl' => base/theme/default/template.tpl

tada!
Back to top
View user's profile Send private message
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Thu Oct 16, 2003 11:06 pm    Post subject: Reply with quote

exactly but i can't seem to get it to work lol
Back to top
View user's profile Send private message Visit poster's website AIM Address
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Fri Oct 17, 2003 1:24 am    Post subject: Reply with quote

ok here is how i have it set now and it sorta works

$this->_smarty->template_dir = $this->_site->_settings->_site_root."/theme/".$this->_site->_user->_theme;

that echo's this

c://inetpub//wwwroot//tfans/theme/themes/default/

but for some odd reason when i do my include i get this

Warning: Smarty error: unable to read template resource: "navmenu.tpl" in c:\inetpub\wwwroot\tfans\smarty\Smarty.class.php on line 1042

why is it still looking in the smarty folder, if it is hehe??
Back to top
View user's profile Send private message Visit poster's website AIM Address
idle0ne
Smarty Rookie


Joined: 16 Oct 2003
Posts: 22
Location: Vermont

PostPosted: Fri Oct 17, 2003 1:29 am    Post subject: Reply with quote

WOOOOHOOOOO I got it to work FINALLY

thanks for all the help Smile
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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