Hello, everyone!

Is there any ability to attach javascript files to specific pages only (e.g. front page) using info file? Could not find anything about it. :(

Thank you.

Comments

Phillip Mc’s picture

I'm not so sure about using the info files but you can use the theme.

There's a few ways of doing that..perhaps the easiest is to copy your page.tpl.php file, rename it page-front.tpl.php and insert your link to the javascript you want to load just after the <?php print $scripts ?> line. example below:

<script type="text/javascript" src="<?php print base_path() . path_to_theme() ?>/yourjs.js"></script>

Where your.js is the name of your javascript file located in your default theme folder.

Alternatively you can use this snippet in your page.tpl.php and copy your javascript into your theme folder.

<?php if ( $is_front ) {?>
  <script type="text/javascript" src="<?php print base_path() . path_to_theme() ?>/yourjs.js"></script>
<?php } ?>

phil

Ustas’s picture

Yeah! This works for me. ;)

Thanks a lot!

Phillip Mc’s picture

hi ustas.

which option did you use? It would be handy to know which one you found easiest.

phil

Ustas’s picture

I have separate template for my front page. So, I used first one.