featurex Posted December 13, 2011 Share Posted December 13, 2011 (edited) 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 December 13, 2011 by featurex (see edit history) Link to comment Share on other sites More sharing options...
CartExpert.net Posted December 13, 2011 Share Posted December 13, 2011 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' Link to comment Share on other sites More sharing options...
featurex Posted December 13, 2011 Author Share Posted December 13, 2011 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 More sharing options...
CartExpert.net Posted December 13, 2011 Share Posted December 13, 2011 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 More sharing options...
featurex Posted December 13, 2011 Author Share Posted December 13, 2011 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 More sharing options...
CartExpert.net Posted December 13, 2011 Share Posted December 13, 2011 Hello! Happy we could help you. Please, change the title of the topic and add '[sOLVED]' to the beginning. Link to comment Share on other sites More sharing options...
sannie Posted April 9, 2012 Share Posted April 9, 2012 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 More sharing options...
Patlia Posted April 10, 2012 Share Posted April 10, 2012 First of all you can not use that on Prestashop, it has to be changed. Link to comment Share on other sites More sharing options...
CartExpert.net Posted April 10, 2012 Share Posted April 10, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now