Re: [SMARTY-DEV] Intelligent JavaScript handling

From: Date: Thu, 18 Mar 2004 09:35:34 +0000
Subject: Re: [SMARTY-DEV] Intelligent JavaScript handling
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2221@lists.php.net to get a copy of this message
In response to comments by Scott Matthewman and boots: I generally agree in principle with Scott, but I think there are (valid) exceptions, and programming style is a matter of preference/experience. Most javascript (or certainly large amounts of javascript) is imho best served by an included script anyway, as the browser can cache it better. However, there are regular FAQs here from people who need to be told to use {literal}, and a smaller but still significant number of those then have problems which require dropping in and out of {literal} to use Smarty tags in the script. Thus {literal} is both required and, in many cases insufficient for script purposes, and while I might be happy to code differently (even "better") to suite {literal}'s limitations, I don't think we should preach to others, and for that matter I don't want to dictate to the guys who design templates for the code I write, since they're usually the client not me. As to whether this is a specific Javascript issue - I don't think it is. For example, the following won't work: {literal} <style> .main { color: {$main.color}; background-color: {$main.bgcolor}; } </style> {/literal} However, switching {literal} for {script}, interpretted as described previously, would work. I don't think it is good programming style to scatter definitions around CSS files (usually the same obscure colour will appear multiple times in the same style definition, making it difficult to maintain, and in any case it shouldn't be necessary to have completely different stylesheets for a simple colour change, so running CSS files through Smarty makes a lot of sense). So this (imho) is a "good programming" case for this functionality. In fact, it is a general issue whenever we want to have a block of text (code/css/whatever) which needs to use { and } but which you also want to use Smarty tags within. Maybe {script} would be the wrong name, but I do think it would be a valuable addition. -- Mark Rogers, More Solutions Ltd :: Tel: 0845 45 89 555

« previous php.smarty.dev (#2221) next »