Re: beginner, (for sure)
| From: | Bertrand DUNOGIER | Date: | Tue, 15 Jan 2002 07:36:54 +0000 |
| Subject: | Re: beginner, (for sure) | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2539@lists.php.net to get a copy of this message | ||
PJP> <?php
PJP> require("Smarty.class.php");
PJP> require ("lib/globals.php");
PJP> $calljava = "<script language=\"JavaScript\"
PJP> src=\"java_scripts/java_sr.js\"></script>\n";
PJP> echo $calljava;
PJP> $smarty = new Smarty;
PJP> //*titles
PJP> $page_titles ["home"] = "[ Home Page ]";
PJP> $page_titles ["portfolios"] = "[ Portfolios ]";
PJP> // bunch more $page_titles here
PJP> $smarty->assign("date",PrintDate("$date"));
PJP> $title = 'my_photography_site';
PJP> $smarty->assign("navigation",
PJP> $smarty->fetch("navigation.tpl"));
PJP> $smarty->assign("navigation1",
PJP> $smarty->fetch("navigation1.tpl"));
PJP> switch ($page)
PJP> {
PJP> case "":
PJP> $smarty->assign(array("title" => "$title"));
PJP> $smarty->assign("Content",
PJP> $smarty->fetch("home.tpl"));
PJP> break;
PJP> default:
PJP> $smarty->assign(array("title" => "$title
PJP> $page_titles[$page]"));
PJP> $smarty->assign("Content",
PJP> $smarty->fetch("$page.tpl"));
PJP> break;
PJP> }
PJP> $smarty->display('index.tpl',$REQUEST_URI);
PJP> $smarty->caching = true;
PJP> ?>
PJP> So anyway, smarty displays it OK.
PJP> I wonder though, whether there is a better way to accomplish this.
Concerning your $calljava variable, you should use in your template
something like:
{section name=java loop=$CALLJAVA}
<script language="JavaScript" src="{$CALLJAVA[js]}"></script>
{/section}
and in your php code:
<?php
...
$calljava[0] = "java_scripts/java_sr.js";
$calljava[1] = "java_scripts/java_sr_2.js";
$tpl->assign(CALLJAVA, $calljava);
...
?>
This way, you can include as many scripts as you want in your HTML
code without this ugly echo.
About your navigation*.tpl, a {include file=navigation.tpl} in the
template would probably be better than the fetches.
in your switch $page,
{include page=$page.tpl}
<?php
...
$tpl->assign(page, $page);
...
?>
shoud also be ok.
PJP> Also, I wonder how to create an array of lets say
PJP> index.tpl, index2.tpl, index3.tpl, with slightly different design layout, and
PJP> depends on which link one happens to click smarty will display according
PJP> index.tpl file?
You could just create several different design in several different
directories in your templates directory:
templates/1/index.tpl
/...
/2/index.tpl
/...
/3/index.tpl
/...
and display the good one according to a link variable, by instance
$tpl->display("$chosenDesign/index.tpl");
--
Bertrand mailto:bdunogier@wanadoo.fr