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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Embed code for a form


4 Posts   851 Views


17 December 2010 at 7:13am Community Member, 98 Posts

I have an "opt in" form to create with code generated by the application I am using. I know that SilverStripe strips out this code, so I found this thread [url][/url] and was able to create the new page type (Embed Page) with my text area to enter my html code in the page in the CMS, but now I'm stupidly at a loss as to what to do next. I tried the next part:

In the CMS you'll get a TextArea where you can paste your iframe code.
In the template you just add $EmbedCode below or above your content. For example:

<div class="typography">

but nothing happens. Nothing is inserted/embedded. Can anyone see what I am missing? Thank you.


17 December 2010 at 9:12am (Last edited: 17 December 2010 9:14am), Community Member, 88 Posts

I don't know if i got it right.
But if you want to output some html/script stuff on your webpage, that has been entered in the backend you can do as follows:

1) add a database field to your class like

static $db = array('myHtmlStuff' => 'Text');

2) in getCMSFields() function of this class add

$myHtmlStuff = new TextareaField('myHtmlStuff', 'HTML Stuff Label');
$fields->addFieldToTab('Root.Content.Main', $myHtmlStuff);

3) in your corresponding add

My HTML Stuff looks like: $myHtmlStuff

4) run /dev/build?flush=all
Now enter some text into this field ('HTML Stuff Label' should now appear in CMS) and check frontend.

Does it work out?


17 December 2010 at 9:32am Community Member, 98 Posts

Thank you, dompie! I kept looking and looking, and (big surprise!) found a typo, then did put the $EmbedCode in the right place, and it did appear. I was hoping that I could actually embed this code in the sidebar so it would appear on each page, but I think that I am happy with it right now. You wouldn't have any idea how to get the code into the sidebar, would you?


17 December 2010 at 10:40am Community Member, 88 Posts

Usually you'd like to create a template file like in your Include folder.

1) in this you write the code you'd like to display on every page

2) put <% include sidebar %> in your files that are located in 'Layout' or 'themes/<mytheme>/' folder

Make sure every page class provides the correct variables or functions you have used in your