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

Basic Question (you would think)


7 Posts   965 Views


28 August 2010 at 4:30am (Last edited: 28 August 2010 4:33am), Community Member, 49 Posts

In a typical .ss file we output a variable like this:


Is there a way to output like this:

IF $Content is empty THEN

PRINT nothing


PRINT <h2>Quote</h2><p>$Content</p>


28 August 2010 at 9:51am (Last edited: 28 August 2010 9:54am), Community Member, 181 Posts

Hi Johan,

There are many things you can do with templates:

essentially, if you wanted to check for the presence of $Content then:

<% if Content %>
<h2>You Have Content :)</h2>
<% else %>
<h2>You have no content :(</h2>
<% end_if %>

Note there is no $ before Content in the condition.

Also take a look at the blackcandy templates for examples of this in action. The [url=]tutorials[/url] are a good place to start too.


28 August 2010 at 10:37am Community Member, 243 Posts


That won't work because content uses the HTML editor field which will mean contact is an empty p tag if the user adds no content.

This means the condition needs to be:

<% if Content.NoHTML %>

Hope that works


28 August 2010 at 11:39am Community Member, 181 Posts

Hey Pigeon,

I remember there being something about empty <p> tags a while back but don't seem to get them any more in 2.4.0. Could be a TinyMCE improvement since then.

Still, Content.NoHTML would be the best way to go in case there's non-displaying markup in the db field, thanks for the tip.


31 August 2010 at 8:29pm (Last edited: 31 August 2010 8:31pm), Community Member, 49 Posts

Thank you all very much.

Shame there are no arrays for multiple content areas so that these fields do not need to be replicated (eg. Content1, Content2 or more accurately link1, link2, link3 etc...)

Good stuff I am really liking Silvertripe.


1 September 2010 at 8:42am Community Member, 181 Posts

Hi Johan,

"Shame there are no arrays for multiple content areas"

That's where Data Objects come in. There aren't any great tutorials or recipes for this and don't have time to give you an example right now but will come back later with something if no one else has stepped in by then.



1 September 2010 at 9:39am Community Member, 509 Posts

For multiple links, you should just be able to create a has many relationship to SiteTree, then generate a TreeMultiSelectField using SiteTree.

Something like:

class Page extends SiteTree {

public static $has_many = array(
'Links' => 'SiteTree'

public function getCmsFields() {
$fields->addFieldToTab('Root.Main.Links',new TreeMultiSelectField('Links','Choose links to appear on page',DataObject::get('SiteTree')));

Then you should be able to loop through those links with something like:


<% if Links %><ul>
<% control Links %><li><a href="$Link">$Title</a></li><% end_control %>
</ul><% end_if %>

I ,literally just plucked that out of the air, so it will probably need a bit of tweeking. The DataObject will need some more complex explination, but there are some useful links:[]=has&s[]=many[]=has&s[]=many

They may be of some help. Also the Silverstripe book has some very handy info in it.

Hope that helps,