ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Reference Javascript

October 11, 2007 3:21pm

Subscribe [0]
  • #1 / Oct 11, 2007 3:21pm

    arandlett

    4 posts

    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

    adamwiggall

    178 posts

    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

    adamwiggall

    178 posts

    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

    arandlett

    4 posts

    public directory, meaning where the initial index.php page is for expressionengine?

  • #5 / Oct 11, 2007 3:51pm

    adamwiggall

    178 posts

    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

    arandlett

    4 posts

    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

    Lisa Wess

    20502 posts

    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

    adamwiggall

    178 posts

    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

    Lisa Wess

    20502 posts

    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

    adamwiggall

    178 posts

    So. Lisa

    How should the full line that contains

    =/scripts/script.js

    look?

    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

    arandlett

    4 posts

    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

    adamwiggall

    178 posts

    I just tried it. Now I’m not working…

  • #13 / Oct 11, 2007 5:02pm

    Lisa Wess

    20502 posts

    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

    adamwiggall

    178 posts

    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

    Lisa Wess

    20502 posts

    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. =)

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases