4

I would really like to use this on a single cms page in magento. For some reason it will not show the content.

page with script

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">// <![CDATA[
mediaid=191156;subid='';entry=25;provider='0';duration=0;renewal=0;daisyconTelecomFilterView=1;col='1111111';programs='all';header='FFFFFF';background_price='E2F0FB';border='ECECEC';button_text='Bekijken';button_color='FF8300';button_hover='FF9E3D';button_textcolor='FFFFFF';font='Arial';slider='3694C7';minMob='0';maxMob='1000';minMin='100';maxMin='3000';minInt='200';maxInt='6000';minAb='0';maxAb='100';mobiles='all';
// ]]></script>
<script type="text/javascript" src="http://developers.affiliateprogramma.eu/mobielvergelijker/general.js"></script>
<script type="text/javascript" src="http://developers.affiliateprogramma.eu/mobielvergelijker/jquery.nouislider.min.js"></script>
asked Mar 24, 2014 at 15:38
2
  • do you want to add js file in every cms page? Commented Mar 24, 2014 at 15:47
  • No on just one page i need above script, tried allready to fix trough xml layout update -->> No go Commented Mar 24, 2014 at 15:50

3 Answers 3

11

Magento has a core/text type block that accepts text input from the layout XML. If you want to add the same files to all the CMS pages add the following to, for example, your local.xml

<cms_page>
 <reference name="header">
 <block type="core/text"><action method="setText">
 <param>
<![CDATA[
 <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
 <script type="text/javascript">mediaid=191156;subid='';entry=25;provider='0';duration=0;renewal=0;daisyconTelecomFilterView=1;col='1111111';programs='all';header='FFFFFF';background_price='E2F0FB';border='ECECEC';button_text='Bekijken';button_color='FF8300';button_hover='FF9E3D';button_textcolor='FFFFFF';font='Arial';slider='3694C7';minMob='0';maxMob='1000';minMin='100';maxMin='3000';minInt='200';maxInt='6000';minAb='0';maxAb='100';mobiles='all';</script>
 <script type="text/javascript" src="http://developers.affiliateprogramma.eu/mobielvergelijker/general.js"></script>
 <script type="text/javascript" src="http://developers.affiliateprogramma.eu/mobielvergelijker/jquery.nouislider.min.js"></script>
 ]]>
 </param>
 </action>
 </block>
 </reference>
</cms_page>

Edit :

If you add these code in particular cms page. Then goto cms > pages then click on your page in design tab you can add the above code with out <cms_page> tag in Layout Update XML

answered Mar 24, 2014 at 15:51
6
  • 1
    that does not work either. :( Commented Mar 24, 2014 at 16:13
  • Did you clear the cache? Are you getting any errors or issues? and did @Meenakshi's method work? Commented Mar 24, 2014 at 16:15
  • cache is disabled, @Meenakshi's method did not work either. there are no errors just a blank page. Commented Mar 24, 2014 at 16:20
  • can you set ini_set('display_errors', 1); in your index page? Commented Mar 24, 2014 at 16:22
  • In the above example there is a <!CDATA[...]]> tag within a <!CDATA[...]]> tag which is not possible (without any tricks). So probably that's what causing it to fail? You should remove the CDATA inside your Javascript tags. Also, this is not necessary/outdated, but that's a whole different discussion out there... Commented Jul 29, 2014 at 13:05
8

Finally got it working. All the javascript files local on server now.

Code below I put in layout update xml field.

<reference name="head">
 <action method="addItem">
 <type>skin_js</type>
 <script>jquery-1.8.3.min.js</script>
 </action>
 <action method="addItem">
 <type>skin_js</type>
 <script>general.js</script>
 </action>
 <action method="addItem">
 <type>skin_js</type>
 <script>jquery.nouislider.min.js</script>
 </action>
 <action method="addItem">
 <type>skin_css</type>
 <script>example.min.css</script>
 </action>
 <action method="addItem">
 <type>skin_css</type>
 <script>example.min.css</script>
 </action>
 <action method="addItem">
 <type>skin_css</type>
 <script>nouislider.fox.css</script>
 </action>
</reference>

The code I use for the content of the page:

<script type="text/javascript">// <![CDATA[
mediaid=171164;subid='smako';entry=25;provider='0';duration=0;renewal=0;daisyconTelecomFilterView=1;col='1111111';programs='all';header='FFFFFF';background_price='E2F0FB';border='ECECEC';button_text='Bekijken';button_color='FF8300';button_hover='FF9E3D';button_textcolor='FFFFFF';font='Arial';slider='3694C7';minMob='0';maxMob='1000';minMin='100';maxMin='3000';minInt='200';maxInt='6000';minAb='0';maxAb='100';mobiles='all';
// ]]></script>
<div id="mobile-comparator-wrapper" class="mobile-comparator-wrapper" style="background-color: #ffffff !important;">&nbsp;</div>
Siarhey Uchukhlebau
16.2k11 gold badges57 silver badges89 bronze badges
answered Mar 26, 2014 at 8:41
2

In admin CMS -> Pages -> Design -> XML Layout Update

<reference name="head">
 <action method="addItem">
 <type>skin_js</type>
 <script>js/filename.js</script>
 </action>
</reference>

Source: (Has an error in the script path, which I fixed here.) http://www.mindfreakerstuff.com/2012/10/add-javascript-css-to-home-page-or-specific-cms-page-magento/

Another option is to inline code as such. Note you'll need a name for the block.

<reference name="head">
 <block type="core/text" name="anal-expe.js" >
 <action method="setText">
 <text>
 <![CDATA[
 <script type="text/javascript">
 alert("you rock!");
 </script>
 ]]>
 </text>
 </action>
 </block>
</reference>
Siarhey Uchukhlebau
16.2k11 gold badges57 silver badges89 bronze badges
answered Apr 27, 2015 at 20:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.