Re: php variable within include
| From: | Kerry Kobashi | Date: | Sun, 08 Dec 2002 16:15:46 +0000 |
| Subject: | Re: php variable within include | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6694@lists.php.net to get a copy of this message | ||
Sorry... answered my own question via:
{include file=$style.css}
Maybe put something in the docs for this in Example 7.6
--------------------------------------------------------
{include file="header.tpl"}
{* body of template goes here *}
{include file="footer.tpl"}
{include file=$style.css}
{* Example of variable substitution and dynamic CSS inclusion *}
Further discussion:
-------------------------------------
By using this simple technique in the TPL:
<head>
<title>{$title}</title>
</head>
<style>{ include file = $style.css}</style>
Style sheets can be loaded inline on the fly via business logic/PHP through
assignment (and cached). No need for browser to pull in via <link> causing
an additional trip to the server. Web designers are happy and pre-existing
CSS files remain intact.
If your style sheets are static and do not get dynamically generated to
cause a dirty cache, this rocks.
Also, no need for Smarty configuration files with #blah# syntax embedded in
the TPL for styling documents.
Anyone know the ramifications of this approach on a multithemed environment
where users have ability to change the style? My hope is that there will be
separate pages cached per theme to avoid recompile every hit. Any thoughts
on this welcomed!
Kerry Kobashi
Kobashi Computing
"Kerry Kobashi" <kkobashi@thegrid.net> wrote in message
news:20021208152727.76837.qmail@pb1.pair.com...
> Is there a way to do the following without coming up with a Smarty error?
>
> {include file = "{$style}.css"}
>
> Fatal error: Smarty: [in myTemplate.tpl line 16]: syntax error: invalid
> attribute name - '$style' in C:\Program Files\Apache
> Group\Apache2\htdocs\MySite\Smarty\Smarty_Compiler.class.php on line 1398
>
> Kerry Kobashi
> Kobashi Computing
>
>
>