Smarty and possibility to parse Javascript-Files?
| From: | Matthias Mohr | Date: | Thu, 06 Mar 2003 11:52:54 +0000 |
| Subject: | Smarty and possibility to parse Javascript-Files? | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8435@lists.php.net to get a copy of this message | ||
I sometimes use Smarty-variables inside my javacript code like this:
(of course I changed the Smarty-delimiters to "<{" and "}>", so that it
will
work inside javascript-code)
-----------------------------------------------------------------------------
<script language="javascript" type="text/javascript">
<!--
function storevalue( Value ) {
var CookieName = "<{$cookiename}>";
set_cookie( CookieName, value );
}
//-->
</script>
-----------------------------------------------------------------------------
in the above (incomplete) example, I use the smarty-variable "cookiename"
as the name of the cookie to which something has to be stored.
So I can easily change my cookiename through an PHP-configuration file.
The templates and also the javascript-code works perfect without knowledge
of the name.
But when I use more complex javascript-code, I would like to have it in
separate Javascript-Files, like that:
-----------------------------------------------------------------------------
<script language="javascript" type="text/javascript"
src="js/CookieMgmt.js">
</script>
-----------------------------------------------------------------------------
So if I put the above javascript-code in the CookieMgmt.js I have (of course)
to remove the smarty-tags.
So the javascript-code has to have the knowledge of the cookiename-variable
or it is incomplete and needs this variable to be set "somewhere else".
So either I must hold the information twice (once in PHP and another time in
the javascript-file)
or I must live with incomplete javascript-code and write it like follows:
-----------------------------------------------------------------------------
<script language="javascript" type="text/javascript">
<!--
var CookieName = "<{$cookiename}>";
//-->
</script>
<script language="javascript" type="text/javascript"
src="js/CookieMgmt.js">
</script>
-----------------------------------------------------------------------------
To come to an conclusion:
I think it would be a nice feature, if smarty would have the possibility to parse
also included javascript-files
what do you think?
with regards,
Matthias