RE: Intelligent JavaScript handling

boots <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
Excellent point, Scott. It also helps lead to abstraction and
refactoring. Another point is that your editor/IDE will be able to
recognize your javascript code properly--always.

Still, just as parameterization has uses, so does meta-programming.
Indeed, there are situations where a meta-replacement is simpler than
parameter passing. This is especially true during the prototyping
phase. Further, if you blindly paramaterized all replacements, you are
likely to end-up sending MORE code (as you will have functions for each
replacement) meaning a larger runtime for the client and more
functional points that will require maintenance.

I think both techniques are very useful and I tend to agree that having
a mechanism that can support those context switches from within Smarty
would be valuable. It doesn't have to be overloaded in the {literal}
tag, though I'm not against that. I think messju and others are being
TOO literal with that tag :) (compare PHP strings allowing embedded
vars and also the prevelance of the backslash escape char) I think a
{script} tag or what-have-you is less appropriate because the issue
isn't related strictly to JS scripting but also appears in other
situations.

xo boots

--- Scott Matthewman <[email protected]> wrote:
> > -----Original Message-----
> > From: Monte Ohrt [mailto:[email protected]] 
> > Sent: 17 March 2004 16:33
> > 
> > Another option is replacing "{" with "{ldelim}" and "}" with 
> > "{rdelim}",
> > since that wasn't mentioned. There usually aren't too many of 
> > them, one
> > pair per javascript function or css definition.
> 
> At the risk of veering off-topic, this particular thread is poitning
> out to
> me (as a developer who uses Smarty)) that people are programming
> JavaScript
> inefficiently.
> 
> If you're using Smarty to write out fresh JavaScript all the time,
> with
> variable values droppen in where necessary, you would be better off
> using
> functions in your JavaScript function definitions, so that the only
> lines
> that need to have Smarty insert variables are the function *calls*.
> 
> If you can get into this habit, then your resultant HTML+Javascript
> will (a)
> generally end up being smaller in size, if two of more blocks of JS
> code can
> be replaced with two calls to one parameterised function; and (b)
> load
> quicker, if you are then able to store your Javascript functions in a
> separate file (i.e., with <script src="..."></script>) which browsers
> can
> then cache independently of however many HTML pages need to use the
> same
> function.
> 
> It'll also make debugging code easier, as you know that the JS code
> won't be
> changing every time you generate a new page from your templates... ;)
> 
> Just my twopenn'orth, as my grandmother used to say,
> 
> Scott


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.