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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

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

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

Form based modules

Go to End

4 Posts   2087 Views


Community Member, 4 Posts

15 February 2007 at 5:59pm

Edited: 15/02/2007 6:09pm

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 :)



Forum Moderator, 801 Posts

15 February 2007 at 6:38pm

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/ 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.


Forum Moderator, 922 Posts

15 February 2007 at 11:29pm

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).


Community Member, 4 Posts

16 February 2007 at 3:51am

Edited: 16/02/2007 4:18am

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.