Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Custom HTML Code / Javascript inserted via CMS


Go to End


10 Posts   8010 Views

Avatar
pinkp

Community Member, 182 Posts

5 March 2013 at 12:21am

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!

Avatar
Craftnet

Community Member, 58 Posts

13 March 2013 at 2:23am

For the future - may be useful to someone

Use a:
- Text or Varchar

In CMSfield normaly like:
- new TextAreaField
- newTextField

In template
$NameField.RAW

Go to Top