|
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 |
asd_pl Smarty n00b
Joined: 09 Nov 2003 Posts: 2
|
Posted: Thu Nov 20, 2003 7:19 pm Post subject: all in one :) |
|
|
i have some problem
i wanna use
[php:1:0c0e2059ef]<?php
switch($_GET['op'])
{
case 'about':
include('about.php');
break;
default:
include('home.php');
break;
}
?>[/php:1:0c0e2059ef] To get all peges in one. How can i do this in Smarty.
The Sencond problem is when i try put this code in index.tpl between {php} and include another file where i have [php:1:0c0e2059ef]<?php
require('C:\usr\Apache\httpd\html\smarty\Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir ='/templates';
$smarty->compile_dir ='/templates_c';
$smarty->config_dir ='/configs';
$smarty->cache_dir ='/cache';
?>[/php:1:0c0e2059ef]
I get an error: Fatal error: Cannot redeclare class smarty in C:\usr\Apache\httpd\html\smarty\Smarty.class.php on line 70
Plz help. thanks |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Nov 20, 2003 9:10 pm Post subject: Re: all in one :) |
|
|
Hi asd.
For your first problem, instead of including the code directly, assign the filename to a template var and then do an {include_php file=$foo}. Sheesh, I can hardly believe I'm suggesting include_php
asd_pl wrote: | The Sencond problem is when i try put this code in index.tpl between {php} and include another file where i have [php:1:49d4e9e3a9]<?php
require('C:\usr\Apache\httpd\html\smarty\Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir ='/templates';
$smarty->compile_dir ='/templates_c';
$smarty->config_dir ='/configs';
$smarty->cache_dir ='/cache';
?>[/php:1:49d4e9e3a9]
I get an error: Fatal error: Cannot redeclare class smarty in C:\usr\Apache\httpd\html\smarty\Smarty.class.php on line 70
|
Uhh, yeah! First, use require_once -- second, why in the world are you defining your smarty apparatus from within a template? Are you aiming for a spanking?
If you want access to the currently running Smarty instance (ie. the instance that called the template in the first place) use $this instead of $smarty from within the {php}...{/php} block. If you need a new Smarty instance from within your template then IMHO, I'd say your design needs a rethink or you are doing something wrong.
My suggstion, as always, is not to bundle your PHP and template code so tightly. Whenever possible, have your PHP applicaiton complete prior to instantiating your templates. |
|
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
|