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>
2
  • do you want to add js file in every cms page? – MeenakshiSundaram R Mar 24 '14 at 15:47
  • No on just one page i need above script, tried allready to fix trough xml layout update -->> No go – user5836 Mar 24 '14 at 15:50
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

6
  • 1
    that does not work either. :( – user5836 Mar 24 '14 at 16:13
  • Did you clear the cache? Are you getting any errors or issues? and did @Meenakshi's method work? – Sander Mangel Mar 24 '14 at 16:15
  • cache is disabled, @Meenakshi's method did not work either. there are no errors just a blank page. – user5836 Mar 24 '14 at 16:20
  • can you set ini_set('display_errors', 1); in your index page? – Sander Mangel Mar 24 '14 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... – 7ochem Jul 29 '14 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>
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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.