SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Nov 24, 2005, 11:03 #1
- Join Date
- Nov 2004
- Location
- Right behind you, watching, always watching.
- Posts
- 5,431
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Smarty template engine and file includes
I've had to integrate a set of mortgage calculators into a site I'm working on. The app uses the Smarty template engine and I'm having some problens trying to figure out how to add in some includes (and or variables) into the template.
On the site I have two specials side bar text areas that are nothing more than includes, work fine. But now after integrating the mortgage calc into the app (and using one of its templates for the layout) I can get these two text files back into the pages.
I have this in the main calculators.php:
PHP Code:include('includes/overall.inc.php');
$smarty->assign('contents',$smarty->fetch('calculators.tpl'));
$smarty->display('main.tpl');
PHP Code:$smarty->assign('specials1',smarty->fetch('/pages/special-news-1.txt');
PHP Code:{$specials1}
OK, scratch that ... went to the smarty site and did some quick reading and found this built in function:
PHP Code:{include file="footer.tpl"}
So now I'm really lost. The functions seem to be working but nothing I try seems to allow smarty (is it really?) to find this file..... any clues here?
BTW, I dont want to move these two text files into the calculator folder as I have the rest of the site's content in the same folder as these ... makes it easier for the customer.
thanks
-
Nov 24, 2005, 13:19 #2
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Hello DC
This is very strange problem you have, as absolute path to the file should definitely do the trick..
The only thing I have noticed with code you provided is on line
PHP Code:$smarty->assign('specials1',smarty->fetch('/pages/special-news-1.txt');
How did you set up template dir and compile dir for smarty? It is higly recommended that you provide absolute paths, to avoid that smarty gets lost with files you want it to read.
$smarty->template_dir = 'full path to the template dir';
$smarty->compile_dir = 'full path to the compile dir';
You could try to debug with smarty's debugging console, but I think it won't work with fetch() API.
Maybe you should try to execute the code you are using for those calculations on mail.php (if that is the filename) and try using (include file="your_template.tpl"); within main.tpl. The relative paths should work! Try dumping $template_dir.
Sorry I couldn't help you more. I'm out of ideas.-- Jelena --
-
Nov 24, 2005, 14:09 #3
- Join Date
- Nov 2004
- Location
- Right behind you, watching, always watching.
- Posts
- 5,431
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah the missing $ was a typo in my post. You may have a point with the path though, I moved the two files I wanted to read into the templates directory and changed the read to this:
PHP Code:$smarty->assign('specials1', $smarty->fetch('special-news-1.txt'));
This is what I have in the overall.inc.php file (the default set up):
PHP Code:/* no cache */
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");
/* turning off NOTICES */
error_reporting(E_ALL ^ E_NOTICE ^ E_USER_NOTICE);
/* full path to calculator dir */
$calcdir = realpath(dirname(__FILE__).'/../');
/* including components */
include($calcdir.'/includes/config.inc.php');
include($calcdir.'/includes/functions.inc.php');
include($calcdir.'/includes/smarty/Smarty.class.php');
/* initialising Smarty engine */
$smarty = new Smarty;
$smarty->template_dir = $calcdir.'/templates';
$smarty->compile_dir = $calcdir.'/includes/smarty/templates_c';
$smarty->assign('config', $config);
/* GZIP compression */
@ob_start("ob_gzhandler");
-
Nov 24, 2005, 14:28 #4
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Yes. I usually do that this way.
PHP Code:define("ROOT", str_replace("\\", "/", realpath(dirname(__FILE__)."/../")."/"));
define("SMARTY_DIR", ROOT."_smarty/libs/");
define("TEMPLATE_DIR", ROOT."_templates/");
define("TEMPLATEC_DIR", ROOT."_templates_c/");
require(SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = TEMPLATE_DIR;
$smarty->compile_dir = TEMPLATEC_DIR;
-- Jelena --
Bookmarks