RE: [SMARTY] combination of if and literal

From: Date: Fri, 07 Mar 2003 10:21:39 +0000
Subject: RE: [SMARTY] combination of if and literal
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8475@lists.php.net to get a copy of this message
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

« previous php.smarty.general (#8475) next »