Forum Discussion

lc-garcia's avatar
11 years ago

Adding a Javascript snippet

Hi all,

 

What's your advice on the best place to add a 10 line Javascript snippet? Should that be a separate file? Can that be added to an existing one?

 

Gracias,

Luis

5 Replies

  • Depends what its for really? The theme wrappers include a hitbox area for analytics tracking for example, you might consider putting it here. Or it could be included and uploaded to html/assets. 

  • HaidongG's avatar
    HaidongG
    Lithium Alumni (Retired)
    11 years ago

    agree with cblown , it really depends what is the JavaScript usage. you can add it with hitbox, skin wrappers directly or upload to html/assets with a reference from skin wrapper.

  • lc-garcia's avatar
    lc-garcia
    Guide
    11 years ago

    It's just a piece of code that selects an option for a dropdown as default.

    Thanks for your reply

  • lc-garcia's avatar
    lc-garcia
    Guide
    11 years ago

    Hi guys,

     

    I think I'm ready with my research here. What I endep doing is using a Custom Content module with some Javascript specific to the type of page I was looking for. 

     

    Gracias,

    Luis

  • Claudius's avatar
    Claudius
    Boss
    9 years ago
    Your reply doesn't seem related to the question of adding JS in a Lithium environment. Although browser developer tools' JS console can be really useful debugging in particular the drupal function reference seems off place here.

    On Lithium it's best practice to use the @liaAddScript directive in the hitbox area of the wrapper. More information here:
    http://community.lithium.com/t5/Developers-Knowledge-Base/Adding-JavaScript-to-components-with-liaAddScript/ta-p/197594