Jump to:

23471 Posts in 18937 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Embed code for a form

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

Page: 1
Go to End
Author Topic: 839 Views
  • jseth
    Avatar
    Community Member
    98 Posts

    Embed code for a form Link to this post

    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 http://silverstripe.org/general-questions/show/7386 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.

  • dompie
    Avatar
    Community Member
    88 Posts

    Re: Embed code for a form Link to this post

    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?

  • jseth
    Avatar
    Community Member
    98 Posts

    Re: Embed code for a form Link to this post

    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?

  • dompie
    Avatar
    Community Member
    88 Posts

    Re: Embed code for a form Link to this post

    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.

    839 Views
Page: 1
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.