Jump to content

Add code/script to header of single page


Recommended Posts

Hello,

 

have a javascript that I want to have activ only on 1 or 2 pages thoughout prestashop.

 

If I just add the code to the header.tpl the script will be active on all pages.

 

But lets say I just want it active on the checkoutpage. How would I achieve this?

 

Thank you for your help.

 

Oliver

 

Found this for wordpress, what would I need to do to use it with prestashop? -----

 

<?php if (is_page('home') ) { ?>

<!--home page custom JS-->

<script type='text/javascript' src="<?php bloginfo('template_directory'); ?>/Scripts/customJS.js"></script>

<?php } ?>

Edited by featurex (see edit history)
Link to comment
Share on other sites

Hello!

 

First of all you can not use that on Prestashop, it has to be changed.

If you want to use it one the checkout page you need to edit 'order-opc.tpl'

 

The code i posted was just an example of how it would look in wordpress. I am looking for a similar peace of code that allows me to use javascript only on certain pages within prestashop. I have to add the code within the header but I only want it activ on a fiew pages.

Link to comment
Share on other sites

Hello!

 

You do not have to add the code to the header. This very much depends on which pages you want the code to be active.

But if you insist on adding it to the header you will need to put 'if' clause in the header and assign a parameter, which will allow the use of the code or not, to smarty from the php scripts.

Link to comment
Share on other sites

Hello!

 

You do not have to add the code to the header. This very much depends on which pages you want the code to be active.

But if you insist on adding it to the header you will need to put 'if' clause in the header and assign a parameter, which will allow the use of the code or not, to smarty from the php scripts.

 

Thx added it to the file you said and its working thx.

Link to comment
Share on other sites

  • 3 months later...

Hi,

 

I want to add script to a custom page I made (I added 2 files: custom.php and custom.tpl as described here http://www.prestashop.com/forums/topic/52650-how-to-add-a-custom-page/).

 

Now I want to add script to this page but am at a lost where to include the script code. If I understand you correctly I just need to add the code to custom.tpl? But if I paste the code in this file (right above {include file="$tpl_dir./breadcrumb.tpl"}), the page won't display correctly (only header shows, rest is blank).

 

Can you please explain me where to paste the code?

 

Many thanks!

 

This is the code:

==

<div id="fb-root"></div>

<script>(function(d, s, id) {

var js, fjs = d.getElementsByTagName(s)[0];

if (d.getElementById(id)) return;

js = d.createElement(s); js.id = id;

js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=100623760070528";

fjs.parentNode.insertBefore(js, fjs);

}(document, 'script', 'facebook-jssdk'));</script>

Link to comment
Share on other sites

Hi,

 

I want to add script to a custom page I made (I added 2 files: custom.php and custom.tpl as described here http://www.prestasho...-a-custom-page/).

 

Now I want to add script to this page but am at a lost where to include the script code. If I understand you correctly I just need to add the code to custom.tpl? But if I paste the code in this file (right above {include file="$tpl_dir./breadcrumb.tpl"}), the page won't display correctly (only header shows, rest is blank).

 

Can you please explain me where to paste the code?

 

Many thanks!

 

This is the code:

==

<div id="fb-root"></div>

<script>(function(d, s, id) {

var js, fjs = d.getElementsByTagName(s)[0];

if (d.getElementById(id)) return;

js = d.createElement(s); js.id = id;

js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=100623760070528";

fjs.parentNode.insertBefore(js, fjs);

}(document, 'script', 'facebook-jssdk'));</script>

 

You can add that code to custom.tpl but HAS to be inside {literal}{/literal} :

{literal}
//put Javascript code here
{/literal}

 

Also you should use

$(document).ready(function(){

})

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...