Jump to content

How to added javascript file in my new template


PTiCA1

Recommended Posts

Posted

Hello,
How can I modify or add new javascript into my new template?

The documentation I found the procedure only to the plugin.

Thank you for your help

Posted

It's just a case of adding

<script type='text/javascript' src='{setting="base_url"}path/to/js/file.js' data-ips></script>

into a template. Probably the most logical place is at the end of

core > global > global > includeJS

Posted

Sorry, my friend, I'm not sure I understand. Do you mean "is there a URL to the JS file?"

It will depend where you store it on your server. If it's at domain.com/uploads/js/my-js-file.js, then you would enter in the template

<script type='text/javascript' src='{setting="base_url"}uploads/js/my-js-file.js' data-ips></script>

({setting="base_url"} gives you domain.com. I use it like that so that nothing goes wrong if I move my site.)

Posted

 

{{$customCss = \IPS\Theme::i()->css( 'custom.css', 'core', 'front' );}}
{{foreach $customCss as $css}}
<link rel='stylesheet' href='{expression="\IPS\Http\Url::external( $css )->setQueryString( 'v', \IPS\SUITE_UNIQUE_KEY )"}' media='all'>
{{endforeach}}

I found a solution for CSS, and exactly same solution I need for Javascript

Posted

That exists because you can create your own custom CSS files when editing a theme. But there's nothing like that for JS.That's why you have to add your JS files manually. (Unless anybody knows any different, in which case I'm happy to learn because I need it too!)

  • 2 years later...
Posted
{{$js = \IPS\Theme::i()->resource( 'folder_in_resources/another_folder/some_js_file.js', 'core', 'front' );}}
<script type="text/javascript" src='{expression="$js->setQueryString( 'v', \IPS\CACHEBUST_KEY )"}'></script>

Using this you can add js files to the theme.  The lines above I included in the includeJS file.

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...