Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » Form based modules

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1662 Views
  • TK421
    Community Member
    4 Posts

    Form based modules Link to this post

    Newbie here, sorry in advance.

    Create form based modules. Designer could throw some tags into a module, then those tags would create input form fields that content could be entered into.

    Ex. Module Name: homepagead1
    <div style="font-size:24px;">$U_headline$</div>
    <div style="color:#009966">$U_subheadline$ <span style="color:#000000;">$U_subheadline2$</span></div>
    <div style="font-size:24px;"><a href="$U_link$"><img src="$U_image$" alt="$U_alt$" width="32" height="32" border="0"></a></div>

    This would then give you 4 or 5 form fields that a user can enter content into... image urls, text, html, etc.

    Then be able to place this module, $%homepagead1%$, module anywhere throughout the site.

    I concepted something similar at work with some developers and it has proven to save time and develops the brand via standardization of presentation. Plus when people see the WYSIWYG editor they get happy and change the standards you have set to 72pt bold red...blinking... this would tame the beast


  • Ingo
    Forum Moderator
    801 Posts

    Re: Form based modules Link to this post

    Hey TK421,

    thanks for your interest in Silverstripe! So basically you want to translate some chunk of structured data (like a "homepage ad") into a template, right?
    The "Silverstripe-way" (based on Model-View-Controller design patterns) of doing this is to create a custom pagetype (e.g. "Homepage") which holds attributes like "advertising text".
    A stub for doing this:
    class Homepage extends Page {
       static $db = array(
          "AdText" => "Text",
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->addFieldsToTab('Root.Main', new TextField('AdText', 'Text for Advertisement'));
          return $fields;
    (Please make sure to visit /db/build after adding this code to /<yourproject>/code/Homepage.php. Also set your page to behave like this pagetype in the "Behaviour"-tab in the CMS)
    You can extend this approach to support more than one textfield by just adding different fields.
    In the true spirit of separating data from presentation, you would then create a template <yourproject>/templates/Homepage.ss for rendering this chunks of data with a specific styling. By this you keep editors from messing up your design.

    If you want to have multiple ads on a page or get an in-depth view on templating, take a look at our tutorials on how to build relationships with DataObjects.

  • Sean
    Forum Moderator
    921 Posts

    Re: Form based modules Link to this post

    The alternative, is you could have some code on Page.php, so that every page that is in the site tree can potentially get this (since everything extends Page at some point).

  • TK421
    Community Member
    4 Posts

    Re: Form based modules Link to this post

    Right on Ingo,

    I will take a look and see what I can figure out. A lot of it seems over my head... but I am not giving up so easily.

    I understand what you are saying in reference to creating custom page types, just not sure where abouts to put the code and where to even track it down.

    I guess if it were an enhancement, the idea would be to give the ability to include modules that are then customizable via the admin screen. Because ideally you would like to be able to swap in modules here and there quickly without going into the code... And then ultimately show a different module based on a different viewer... but I wont get into all that.

    Thanks for the suggestions, I truly appreciate it.

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.