Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » Custom HTML Code / Javascript inserted via CMS

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2682 Views
  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Custom HTML Code / Javascript inserted via CMS Link to this post

    I dont know if this got resolved, or if its written somewhere else but this is my FIX:

    Use a:
    HTMLText
    TextareaField

    Then in the CMS wrap your pasted code in:
    <!-- MYcode -->
    YOUR CODE HERE
    <!--End MYcode-->

    So for example my Rebel Mouse page this is my code:

    RebelMousePage.php

    <?php
    class RebelMousePage extends Page {

       public static $db = array(
       'RebelMouseCode' => 'HTMLText'
       );

    public function getCMSFields() {

    $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.RebelMouseCode', TextAreaField::create('RebelMouseCode','Paste Your Rebel Mouse Code Here: '));
          return $fields;
    }

    }
    class RebelMousePage_Controller extends Page_Controller {
    }

    And in the CMS:

    <!-- RebelMouse -->
    <script type="text/javascript" id="rebelmouse-embed-script" src="https://www.rebelmouse.com/static/js-build/embed/embed.js?site=USER&amp;height=1500&amp;flexible=1&amp;skip=about-site,show_rebelnav"></script><!--End RebelMouse-->

    In the RebelMousePage.ss

    $RebelMouseCode

    hope this helps someone!

  • Craftnet
    Avatar
    Community Member
    58 Posts

    Re: Custom HTML Code / Javascript inserted via CMS Link to this post

    For the future - may be useful to someone

    Use a:
    - Text or Varchar

    In CMSfield normaly like:
    - new TextAreaField
    - newTextField

    In template
    $NameField.RAW

    2682 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.