|
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 |
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Tue Apr 28, 2009 3:24 pm Post subject: include file - path needed? |
|
|
I have an include similar to this one:
Code: |
<{include file='highlights_row.tpl' }>
|
However it can't find the file. Does it work similar to the PHP include where it looks in the current working directory? I was thinking that it looked in the directory that the template was in.
There is definitely a file of that name in the same directory as the including template.
If it looks in the current working directory, is there a way I can do something similar to this PHP code?
Code: |
include(dirname(__FILE__).'/test.php');
|
|
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Tue Apr 28, 2009 5:29 pm Post subject: Case sensitive? |
|
|
If you are on a Linux server, please check for the case of the filenames. It must match (upper case and lower case filenames are different, unlike Windows).
If youa re under Windows, and this script does not run, you may not have the vaild file name there, or your OS has specific limitation to disallow using/accessing this file.
In your case, you must put highlights_row.tpl in the same directory where the .tpl is running from. Normally, it is Smarty's template directory ( $smarty->template_dir ) in the config. So, do not get confused with php directory and template directory. Possibly, you put the .tpl file in php directory.
If you are in a php file, you can check the existence of the template by:
Code: | if($smarty->template_exists('highlights_row.tpl'))
{
$smarty->display('highlights_row.tpl');
}
else
{
// what if file was not found...
} |
This is a demonstration only, and may not solve your exact problem.
And for general use; if you would like to access the file in php's working directory into Smarty's template, as if it is parsed with {php}..{/php}, the below code may help (for advanced users only, in a template file):
Quote: | ... .tpl ...
{'highlights.php'|include_once}
... .tpl ... |
The main thing is that include_once modifier function does not exist in Smarty. So, it tries to execute another callable function, that ultimately becomes a php function. So, it will search the file in php's working directory instead of Smarty's template directory.
Thats the difference there.
Does it help you undersand more? Please write me. |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Tue Apr 28, 2009 5:45 pm Post subject: |
|
|
Thanks, i understand how include works now.
My problem is, the way my templates are set up, I would like to be able to do something similar to this:
Code: |
include(dirname(__FILE__).'/test.php');
|
Translate that to Smarty, and it means: get the directory that this file is in, then include the file test.tpl which is in this directory.
Due to how my CMS works, template files are in many directories. For example:
1. Template A is including Template B which is in another directory (the path to Template B is passed in as a template variable).
2. Template B needs to include Template C which is in the same dir as itself. How can I put an include in Template B so that it can find Template C located in ITS OWN directory. |
|
Back to top |
|
alokin Smarty Regular
Joined: 14 Apr 2009 Posts: 96 Location: Belgrade, Serbia
|
Posted: Tue Apr 28, 2009 8:44 pm Post subject: |
|
|
As far as I know, that dirname solution is not possible in Smarty... You should include that template C the same way you've included template B in template A, i.e.:
Code: |
//template A
{include file = 'path/to/B.tpl'}
//template B
{include file = 'path/to/C.tpl'}
|
That path/to is relative to the path you set for Smarty template_dir. _________________ www.nikolaposa.in.rs |
|
Back to top |
|
sray Smarty n00b
Joined: 09 May 2009 Posts: 2
|
|
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
|