tpl files + javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
taldos
Forum Commoner
Posts: 39
Joined: Mon Aug 23, 2004 8:47 am
Location: Philadelphia

tpl files + javascript

Post by taldos »

quick newbie question.

Is there a trick to making javascript work when using tpl files. I have created an html file and written some code for form validation. However, once I switch the extention to tpl javascript stops working. Is there a way for me to still use this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a browser may not now what to do with such a file if directly loaded. In fact, it shouldn't. A tpl file is meant to be processed by the server.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: tpl files + javascript

Post by Roja »

taldos wrote:quick newbie question.

Is there a trick to making javascript work when using tpl files. I have created an html file and written some code for form validation. However, once I switch the extention to tpl javascript stops working. Is there a way for me to still use this.
Your phrasing is unclear, but I suspect I know what you mean.

In Smarty, when you put javascript into a template file, you have to use literal tags.

http://smarty.incutio.com/?page=SmartyF ... template-3

However, a much better solution is to have the javascript in a standalone file, and reference the javascript file in your html. That way, the javascript file can be cached - saving piles of download time and bandwidth!

Code: Select all

<script type="text/javascript" defer="defer" src="backends/javascript/clear_default.js"></script>
Post Reply