| Author |
Re: [SMARTY] Template inside template
|
|
| Rainer Müller 2005-01-08, 8:57 pm |
| HarryG wrote:
> Hi
>
> I want to have an index.php which is contructed by four templates
>
> index.tpl
> menu.tpl
> content.tpl
> footer.tpl
Use $smarty->display('index.tpl'); and in index.tpl you can specify more
includes for other templates {include file="menu.tpl"}.
All assigned variables are also available in the included templates.
Rainer
| |
| HarryG 2005-01-08, 8:57 pm |
| Thanks Rainer, I will try that.
"Rainer Müller" <mueller_rainer@gmx.de> wrote in message
news:crpe4o$tnb$1@sea.gmane.org...
> HarryG wrote:
>
> Use $smarty->display('index.tpl'); and in index.tpl you can specify more
> includes for other templates {include file="menu.tpl"}.
> All assigned variables are also available in the included templates.
>
> Rainer
| |
| HarryG 2005-01-08, 8:57 pm |
| But will this also call the menu.php. Because there will be queries that
need to be run before the menu.tpl can be displayed.
So do I have to in index.php do something like this and in index.tpl
-index.php-
switch($_GET['manage'])
{
case "pages": $mypage->assign('IncludeFile', "pages.tpl"); break;
case "users": print "hohoho"; include 'users.php'; break;
-index.tpl-
{if $IncludeFile!=""}
{include file="$IncludeFile"}
{/if}
"Rainer Müller" <mueller_rainer@gmx.de> wrote in message
news:crpe4o$tnb$1@sea.gmane.org...
> HarryG wrote:
>
> Use $smarty->display('index.tpl'); and in index.tpl you can specify more
> includes for other templates {include file="menu.tpl"}.
> All assigned variables are also available in the included templates.
>
> Rainer
| |
| Rainer Müller 2005-01-08, 8:57 pm |
| HarryG wrote:
> But will this also call the menu.php. Because there will be queries that
> need to be run before the menu.tpl can be displayed.
No, you have to include the menu.php normally into your php code with:
--index.php--
<?php
// ...
include 'menu.php';
// ...
$smarty->display('index.tpl'); //with {include file="menu.tpl"} inside
?>
--menu.php--
<?php
// your queries and stuff...
// the $smarty object comes directly from index.php
$smarty->assign('menu', $menu); //example
?>
--index.tpl--
<DOCTYPE...>
<html>
<head>...</head>
<body>
....
{* the template which will loop through $menu and output it *}
{include file="menu.tpl"}
....
</body>
</html>
Rainer
| |
| David Zülke 2005-01-08, 8:57 pm |
| You'd usually include menu.php using {include_php} inside the index.tpl.
David
> -----Original Message-----
> From: news [mailto:news@sea.gmane.org] On Behalf Of Rainer M=FCller
> Sent: Sunday, January 09, 2005 12:58 AM
> To: smarty-general@lists.php.net
> Subject: Re: [SMARTY] Template inside template
>=20
> HarryG wrote:
that[color=darkred]
>=20
> No, you have to include the menu.php normally into your php code with:
> --index.php--
> <?php
> // ...
> include 'menu.php';
> // ...
> $smarty->display('index.tpl'); //with {include file=3D"menu.tpl"} =
inside
> ?>
>=20
> --menu.php--
> <?php
> // your queries and stuff...
>=20
> // the $smarty object comes directly from index.php
> $smarty->assign('menu', $menu); //example
> ?>
>=20
> --index.tpl--
> <DOCTYPE...>
> <html>
> <head>...</head>
> <body>
> ...
> {* the template which will loop through $menu and output it *}
> {include file=3D"menu.tpl"}
> ...
> </body>
> </html>
>=20
> Rainer
>=20
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>=20
| |
| Rainer Müller 2005-01-08, 8:57 pm |
| David Zülke wrote:
> You'd usually include menu.php using {include_php} inside the index.tpl.
I don't like that. It breaks the outline of a script and shows you a
wrong list of "required" files.
Rainer
|
|
|
|