Re: [SMARTY] combination of if and literal
| From: | Fritzek | Date: | Fri, 07 Mar 2003 13:00:21 +0000 |
| Subject: | Re: [SMARTY] combination of if and literal | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8478@lists.php.net to get a copy of this message | ||
Hi Sasha,
from my point of understanding the smarty parser: there is a 'IF' and the
condition doesn't fit, ignore whatever comes til the '/IF' (and this
includes a literal as well because it's part of the inner region of the IF).
If I'm wrong what is the sense of IF?
Anyway, the previous answer from the group works for me. Thanks to all
Fritz
"Dr. Sasha Von Stahl" <svs-list-smarty@ratio.net> schrieb im Newsbeitrag
news:!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAA0DrMdtOXoUyIPw1pCX9xZ8KA
AAAQAAAAn72ubc34uU2YPCoGDSz0jgEAAAAA@ratio.net...
> Hi Fritz:
>
> the 'literal' is executed in all cases because the parser does not care
> if 'literal' is woven into an if-statement. 'literal' means literally
> 'take this code as it is and don't ask me what and when'.
> There might be an more elegant solution but I would suggest that you use
> either an external JavaScript file and do the following:
>
> { if ($usescript == 'Y') }
> <script src="filename.js" type="JavaScript"></script>
> { /if }
>
> (Creating an external java script file is quite simple. Simply save your
> java script as a text file with a .js extension on it.)
>
> Or you could use a PHP/Smarty 'include' statement instead, which then
> includes the JavaScript (enclosed with the 'literal' tags in the
> external include-file) only if your condition is 'Y'.
>
> I suggest that you use the external JavaScript file since search engines
> (I know, that's an other subject, but anyway) don't like a lot of
> JavaScript in your parsed page and see external JavaScripts as a reason
> to rank your site/page higher/better.
>
> Kindest Regards,
> Dr. Sasha von Stahl, Ph.D.
>
> Ratio WebServices - the way things work...
> URL: http://www.ratio.net
> eMail: vonStahl |.at.| ratio.net
>
> They that can give up essential liberty to obtain a little temporary
> safety deserve neither liberty nor safety.
> - Benjamin Franklin
>
>
> -----Original Message-----
> From: Fritzek [mailto:fthielem@mplace.de]
> Sent: Friday, March 07, 2003 3:56 AM
> To: smarty-general@lists.php.net
> Subject: [SMARTY] combination of if and literal
>
>
> Hi folks,
>
> I have a template which should only provide a piece of javascript to one
> php-file. I have assigned a variable called usescript and filled with
> 'Y'.
> in the template I have the following code snippet
>
> { if ($usescript == 'Y') }
> {literal}
> <SCRIPT>
> ...
> </SCRIPT>
> {/literal}
> { /if }
>
> But the javascript will be perfomed for all php-file (with or without
> usescript) :(
>
> Whats wrong on my code?
>
> Thanks in advance
>
> Fritz Thielemann
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>