Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

How to add script to head tag for certain pages only Rate Topic   - - - - -

 
  • jeffshead
  • Member
  • Members
  • Join Date: 15-May 08
  • 121 posts

Posted 19 July 2012 - 06:07 AM #1

I want to add or include the following in the head tag:

<script type="text/javascript" src="/include/js/windowResize.js"></script>

I know how to add this so it's included on every page, but I want it in the header of only one page.

I've done this before when developing a site that uses a different CMS package that utilizes Smarty.

What I did then, was to add {$smarty.capture.header} just before the closing head tag in the global header template file. Then when I wanted something added to the head tag, for a specific page, I would add something like...
{capture name="header"}<script type="text/javascript" src="/include/js/windowResize.js"></script>{/capture}
... to the top of that pages template.

I can't get this to work for CS-Cart 3.x

To be more specific, I want to add a certain JavaScript source to the head tag of the checkout page.

Is this possible without adding it to every page?

I tried adding the following just above the closing head tag of 'skins\basic\customer\index.tpl' and I also tried adding it to the bottom of 'skins\basic\customer\common_templates\scripts.tpl'
{$smarty.capture.header}

And the following to 'skins\basic\customer\views\checkout\checkout.tpl'
{capture name="header"}<script type="text/javascript" src="/include/js/windowResize.js"></script>{/capture}

CS-Cart 4.6.3 SP1

 
  • dvsgr
  • Senior Member
  • Authorized Reseller
  • Join Date: 14-Apr 09
  • 1454 posts

Posted 19 July 2012 - 07:25 AM #2

Hi
You need to use the hooks system.

There is a hook for the checkout page so you can put in my_changes folder of your skin in addons folder, a new folder called checkout and then create a file scripts.pre.tpl with this script inside.

To be honest I haven't tried it in v3 but this is how it's done in v2 so it must be similar.

Have a look also in this article kb.cs-cart.com/tracking-code-addition

Fotis
Fotis Kourmadas
Cs-Cart Development - Cs-Cart Authorized Reseller 

 
  • jeffshead
  • Member
  • Members
  • Join Date: 15-May 08
  • 121 posts

Posted 21 July 2012 - 01:57 AM #3

Fotis, thanks for the tip but that does not work. I don't think the hooks work that way.

If I want to add a file named 'scripts.pre.tpl', it has to be added to the '\skins\basic\customer\addons\my_changes\hooks\index' folder but that adds the contents of 'scripts.pre.tpl' to every page because 'script.tpl' loads in every page.

Unless I'm too tired and blurry eyed, I think that article you mentioned verifies what I'm saying.

Thanks,

Jeff :grin:
CS-Cart 4.6.3 SP1

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12038 posts

Posted 21 July 2012 - 07:49 PM #4

Put your info in your scripts.post.tpl file inside:
{if $controller == 'checkout' }
Your script code here
{/if}
This will include your changes on all pages related to 'checkout'. If you want to be specific on the MODE or the STEP, then you'll have to add additional conditions to the if statement.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • jeffshead
  • Member
  • Members
  • Join Date: 15-May 08
  • 121 posts

Posted 22 July 2012 - 01:56 PM #5

tbirnseth, that's exactly what I was looking for.

Thank you :grin:

I read about controllers (http://docs.cs-cart....ocs-controllers) but there's not a lot of info on them.

Can you give me a code example if I wanted to make this checkout step number three specific?

Is there a list of all of the available controllers, steps and modes variables?
CS-Cart 4.6.3 SP1

 
  • Party
  • Advanced Member
  • Members
  • Join Date: 01-Sep 12
  • 66 posts

Posted 15 January 2014 - 06:13 PM #6

I read about controllers (http://docs.cs-cart....ocs-controllers) but there's not a lot of info on them.


Hi jeffshead,

,

I'm wondering if you found a solution to insert the script into a single page?
I'm having difficulties to do this as well. Will appreciate your help!

 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12038 posts

Posted 15 January 2014 - 10:53 PM #7

Wrap it in something like:
{if $controller == 'checkout' and $mode == 'summary'}
{literal}
<script>your_js_code_here();</script>
{/literal}
{/if}
If you need it for a particular 'page' (in cs-cart vernacular), then your if condition would look more like:
{if $controller == 'pages' && $mode== 'view' && $smarty.request.page_id == 123}
Where '123' is the page ID of the page you are interested in.

EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • mancup
  • Member
  • Members
  • Join Date: 27-Dec 12
  • 33 posts

Posted 02 October 2017 - 04:19 PM #8

Hello,

 

I want to add a script into the head only for order.complete page (not checkout pages)

How can I do that I tried in scripts.tpl :

 

{if $controller == 'checkout' and $mode == 'complete'}

....

{/if}



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 12038 posts

Posted 02 October 2017 - 07:06 PM #9

Do you mean hooks/index/scripts.post.tpl in some addon like my_changes?   You should probably be using $runtime.controller and $runtime.mode. But you can verify by using:

<!-- mytag: controller={$controller}, mode={$mode} -->

And then searching the page source (or use browser inspector) for 'mytag:' and seeing what you get.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • The Tool
  • Been Here Way Too Long Member
  • Members
  • Join Date: 30-Mar 07
  • 3964 posts

Posted 02 October 2017 - 07:48 PM #10

It would probably be easiest to go to: Design->Layouts->Order landing page->Click gear icon and add to the Custom HTML code area.



 
  • sioulisn
  • Junior Member
  • Trial users
  • Join Date: 06-Apr 09
  • 74 posts

Posted 19 October 2020 - 10:51 AM #11

I have this at design/template/backend/addons.... x.post.tpl

now it shows correctly in my admin but the script goes to all admin pages.

Is there any way to add it only at specific controller? for example:   order_management.add

I tried to add 

{if $addons.XX.XX && $addons.admin.TT== 'Y' && $controller == 'order_management' && $mode == 'add'}

 

but is not working the code is not showing anywhere after i add it

{if $addons.XX.XX && $addons.YYY.TT== 'Y' }
    <script type="text/javascript" ...}"></script>
    <script type="text/javascript" data-no-defer>
        ...
    </script>
    {script src=...no-defer=true}
{/if}


 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 21726 posts

Posted 19 October 2020 - 02:05 PM #12

Use

{$runtime.controller}

and

{$runtime.mode}

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    Multi-Vendor PLUS           USD 3100 (2775)
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      Multi-Vendor Ultimate       USD 7500 (6000)

 
  • sioulisn
  • Junior Member
  • Trial users
  • Join Date: 06-Apr 09
  • 74 posts

Posted 19 October 2020 - 02:32 PM #13

Works! you are great!

Thank you!

 

 

Use

{$runtime.controller}

and

{$runtime.mode}