Smarty not calling external javascript files correctly?
I have a bit of a weird problem that I can't seem to resolve. I'm trying to call a javascript function from a file outside of my smarty template directory and it doesn't seem to be working. In my smarty file, I have:
<script type='text/javascript' src= '../functions/editConcert.js'></script>
<f开发者_如何转开发orm>
<input type="button" value="Edit Info" onclick="editInfo();">
</form>
And in my editConcert.js file, I have (for testing purposes):
function editInfo(){
alert("I get here");
}
My directory structure looks like this:
Classes
-FillConcertInfo.php (this calls the smarty display function)
Templates
-editConcert.tpl
Javascript
-editConcert.js
I cannot for the life of me figure out what's going on. It works fine in a normal php/html page but smarty seems to be throwing it out the wayside. Any help would be much appreciated.
EDIT: It should be worth noting that adding the following to my smarty template works, but I'd like to use an external file:
{literal}
<script>
function editInfo(){
alert("I get here");
}
</script>
{/literal}
I suspect the js file is not linked properly and is not being found. Be sure the resource is being loaded. If not, fix the path.
Smarty does not affect the loading of external resources sent to the client, as they are requested by the client. Adding the javascript in the template works because then the function is defined where a broken link to an external resource would have the function be undefined.
Open Firebug/Chrome inspector and look at the network information and see if the external javascript page is being loaded or, most likely, has a status of 404. Check your directories and that should fix the issue.
精彩评论