By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,938 Members | 2,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,938 IT Pros & Developers. It's quick & easy.

smarty simple question?

P: n/a
i'm newcomer in using smarty and i have problem like this:
i want to have one template file (e.g. index.tpl) in this file section
which use variable {$content}.
and two files *.php which are using the same template index.tpl and
only change the content.

for example:
/*index.php*/
$smarty = new MySmarty();
$smarty->assign('content','INDEX');
/*about.php*/
$smarty=new MySmarty();
$smarty->assign('content','ABOUT');

how to do this, because this way it doesn't work?

Jun 7 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jun 7, 5:52 am, Gene <ox.g...@wp.plwrote:
i'm newcomer in using smarty and i have problem like this:
i want to have one template file (e.g. index.tpl) in this file section
which use variable {$content}.
and two files *.php which are using the same template index.tpl and
only change the content.

for example:
/*index.php*/
$smarty = new MySmarty();
$smarty->assign('content','INDEX');
/*about.php*/
$smarty=new MySmarty();
$smarty->assign('content','ABOUT');

how to do this, because this way it doesn't work?
give your second inherited MySmarty() object a different reference
name:
....
/*about.php*/
$smarty2 = new MySmarty();
$smarty2->assign('content','ABOUT');

hth,

gk

Jun 7 '07 #2

P: n/a
Gene wrote:
i'm newcomer in using smarty and i have problem like this:
i want to have one template file (e.g. index.tpl) in this file section
which use variable {$content}.
and two files *.php which are using the same template index.tpl and
only change the content.

for example:
/*index.php*/
$smarty = new MySmarty();
$smarty->assign('content','INDEX');
/*about.php*/
$smarty=new MySmarty();
$smarty->assign('content','ABOUT');

how to do this, because this way it doesn't work?

You can include php files in smarty
(http://smarty.php.net/manual/en/lang...nclude.php.php)

{if $content == "INDEX"}
{include_php file="index.php"}
{elseif $content == "ABOUT"}
{include_php file="about.php"}
{/if

The much better way is to include also templates for different content
with include (http://smarty.php.net/manual/en/lang...on.include.php)

{if $content == "INDEX"}
{include file="index.tpl"}
{elseif $content == "ABOUT"}
{include file="about.tpl"}
{/if
Jun 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.