Jump to content

How do I add scripts to a CMS page?


Aalaa

Recommended Posts

I've been trying to add a script to a CMS page and it doesn't appear. I tried using the literal tag as suggested by previous posts, that didn't work as well. I also tried editing the pages from the source but I couldn't find location of the files. Is it possible there is a way to use scripts on CMS pages?

 

Thank you!

Link to comment
Share on other sites

1. I put the script between the literal tags.

2. I'm using prestashop version 1.5.3.1

 

But doesn't the template file change all the CMS pages? I only need to add the script to one specific page.

 

Thanks!

Link to comment
Share on other sites

1. where exactly, by this i mean what file you changed? (literal tags doesnt work in editor in preferences -> CMS)

 

you can add simple {if} condition where you can check id of the CMS page. i mean:

 

{if $cms->id==1}

{literal}

SCRIPT CODE HERE

{/literal}

{/if}

 

 

$cms->id==1

1 is an ID of the cms page for which you want to include script. you can get ID of cms page in preferences -> CMS

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

I used the literal tags in the CMS page editor. I just tried your code in the same editor it doesn't work. Should I use it somewhere else? Sorry I'm a newbie I guess I'll figure it out sooner or later.

 

Thanks.

Link to comment
Share on other sites

I used the literal tags in the CMS page editor. I just tried your code in the same editor it doesn't work. Should I use it somewhere else? Sorry I'm a newbie I guess I'll figure it out sooner or later.

 

Thanks.

 

you don't have to use it in editor.

1. where exactly, by this i mean what file you changed? (literal tags doesnt work in editor in preferences -> CMS)

 

 

you have to edit cms.tpl file located in your theme directory.

Link to comment
Share on other sites

  • 1 year later...

1. where exactly, by this i mean what file you changed? (literal tags doesnt work in editor in preferences -> CMS)

 

you can add simple {if} condition where you can check id of the CMS page. i mean:

 

{if $cms->id==1}

{literal}

SCRIPT CODE HERE

{/literal}

{/if}

 

 

$cms->id==1

1 is an ID of the cms page for which you want to include script. you can get ID of cms page in preferences -> CMS

Thx, it works!!))

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

Don't know if it is the correct way or the wrong but It worked.

Here how I did it.

 

Added literal at the below of the cms.tpl

{if $cms->id==3}
{literal}
<script type="text/javascript" src="mycustom.js"></script>
{/literal}
{/if}

then put the mycustom.js file in the directory /themes/mytheme/js/autoload

 

I am on 1.6

Link to comment
Share on other sites

  • 1 year later...

Hello  

 

 

I try this method but somehow doesn't work for me 100% 

<div class="rte{if $content_only} content_only{/if}"> {$cms->content} 
  {if $cms->id==46}
    <div style="padding:50px;" id="zurmoExternalWebForm"> FORM 
     {literal} 
    <script type="text/javascript" src="http://myweb.com/go/app/index.php/contacts/external/sourceFiles?id=1"></script> 
     {/literal} 
    </div>
  {/if} 
</div>

Appear div with text "FORM" but javascript doesn't work.  

some ideas ? 

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

Hello, in 1.6.1.1 this method puts the script below footer.

at the end of cms.tpl

{if $cms->id==10}
{literal}
<script src="https://www.cetelem.es/contenidos/ecommerce/info.js?partner=*****"  charset="UTF-8" type="text/javascript"></script>
{/literal}
{/if}

script.thumb.png.bdbef3a78aa38bd48e84bd5eac7271f9.png

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

  • 1 month later...

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...