简体   繁体   中英

Linking to external Javascript-file from .tpl does not work

I have a script for a navigation menu which works properly in a combination of JS, CSS and html. But if I place the html-code into a .tpl-File which uses Smarty, it doesn't work anymore, obviously the links, which refer to the external JS-files, are simply ignored:

<script src="menu/js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="menu/js/jquery.menu.min.js" type="text/javascript"></script>

Am I missing something?

If I place the JS-function straight into the .tpl, it works well, but the response time of the page is pretty slow then. I have a sense that is because of the big bunch of JS-code in my .tpl-file, or does it make no difference?

Nonetheless, I think the links to external files should work somehow.

There should be no problem with what you are doing here, but make sure that you refer to the correct placement of your JavaScript-file.

For example if the script is placed in a folder inside your templates directory:

<script type='text/javascript' src='/templates/jquery/dropdown.js'></script>

This indicates the following placement of the file:

[doc_root]/templates/jquery/

as you do not open with " / " in your include-code, the code implements that the position of the file is relative to the current position.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM