If I create a new javascript template how do I then reference that javascript in my html?
What is the URL Relative reference to the site folder you are using to store resources?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
October 11, 2007 3:21pm
Subscribe [0]#1 / Oct 11, 2007 3:21pm
If I create a new javascript template how do I then reference that javascript in my html?
What is the URL Relative reference to the site folder you are using to store resources?
#2 / Oct 11, 2007 3:27pm
I have used the following (which I found on another thread). It works just fine.
I assumes you have a js file called ‘example.js’ in a folder called ‘scripts’ in the public html directory.
Adam.
#3 / Oct 11, 2007 3:28pm
For some reason the code is being stripped. (Just worked it out—script tages)
Here it is without the formatting.
so start the script tag then put <pre><code> src=”{path="scripts/example.js"}” type=“text/javascript”><pre><code>
Then close the script tag.
#4 / Oct 11, 2007 3:36pm
public directory, meaning where the initial index.php page is for expressionengine?
#5 / Oct 11, 2007 3:51pm
In the root of your site you should have a directory called “public_html”. That has the index.php, path.php etc…
Put the scripts folder in there, and the path settings should find it.
It works for me, I think I got it from another thread, I hope it works for you.
Adam
#6 / Oct 11, 2007 4:39pm
when I use that it adds the index.php? before the scripts folder thus not allowing the link to properly fit as well as after the example.js it adds a “/”. Weird?
#7 / Oct 11, 2007 4:42pm
Yes, path= is a special variable to use EE information, and links to a template group and template. If you’re linking to a file on the server, try just using =/scripts/script.js =)
#8 / Oct 11, 2007 4:44pm
Lisa
Am I then correct in presuming it works for me because I have removed index.php using the htaccess file?
Adam
#9 / Oct 11, 2007 4:49pm
Yes, Adam, it’s kind of a lucky coincidence in your case; path= should only be used for links internal to EE. =)
#10 / Oct 11, 2007 4:55pm
So. Lisa
How should the full line that contains
=/scripts/script.jslook?
Like
<opening script tag src=/scripts/script.js type="text/javascript"> <closing script tag>Or do we need something else?
Adam
#11 / Oct 11, 2007 4:57pm
that would do it. It works for me now. Just make sure you have quotations around “/scripts/script.js”
#12 / Oct 11, 2007 5:02pm
I just tried it. Now I’m not working…
#13 / Oct 11, 2007 5:02pm
It should look like any other HTML page including JS =)
<script type="text/javascript" src="/jquery/curl/curl.js"></script>is an example from my page.
#14 / Oct 11, 2007 5:09pm
Okay, sorry.
Big stupid has it going again.
Don’t you just hate it when happy coincidences lead you astray…
Thanks All
#15 / Oct 11, 2007 5:13pm
You know, you can use happy coincidences - I hadn’t even thought of that particular approach as working. It’s not stupid, it’s quite clever. =)