Jump to content
  • 0
Aalaa

How do I add scripts to a CMS page?

Question

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!

Share this post


Link to post
Share on other sites

12 answers to this question

Recommended Posts

  • 0

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!

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

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.

Share this post


Link to post
Share on other sites
  • 0

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!!))

Share this post


Link to post
Share on other sites
  • 0

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

Share this post


Link to post
Share on other sites
  • 0

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 ? 

Share this post


Link to post
Share on other sites
  • 0
On 11/23/2017 at 1:10 AM, colives said:

Sorry for the silly question but, where is cms.tpl in PS7???????

 

Thanks!!


Hi..in Prestashop 1.7 .xx not a cms.tpl file

you can put your code here
themes/your_themes/templates/cms/page.tpl

Thanks

Share this post


Link to post
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

×