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


Reply


4 Posts   860 Views

Avatar
jseth

Community Member, 98 Posts

17 December 2010 at 7:13am

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]http://silverstripe.org/general-questions/show/7386[/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">
<h2>$Title</h2>
$Content
$EmbedCode
</div>

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

Avatar
dompie

Community Member, 88 Posts

17 December 2010 at 9:12am

Edited: 17/12/2010 9:14am

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 tempalte.ss 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?

Avatar
jseth

Community Member, 98 Posts

17 December 2010 at 9:32am

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?

Avatar
dompie

Community Member, 88 Posts

17 December 2010 at 10:40am

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

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

2) put <% include sidebar %> in your template.ss 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 sidebar.ss.