As willr suggested though, you can still use the field name. Then you have a reusable method in your Page class that can be utilised throughout your site, and you won't need to create a separate method for every field you want to test. This is what I did:
public function FieldIsPopulated($fieldName)
if (strlen(trim($this->$fieldName)) > 0)
<% if FieldIsPopulated(Commendations) %>
<% end_if %>
<% if FieldIsPopulated(Notes) %>
<% end_if %>
Willr, I just realised that the function as you suggested works great in the page that you are viewing, but not in a control loop when referring to a property of an iterated item. Any idea how to make this work?
Can anybody explain exactly why it works universally in the model, but not in the controller. Or at least point me in the direction of a document than can help explain. It would benefit me greatly in my understanding of SilverStripe's insides!
I remember finding this confusing at first, but I guess it isn't really. I just hope I can explain it clearly :-) This is how I understand it:
Each template is 'managed' by a controller. Every property/method-call from within a template is answered by the boss controller. Within each template we can use <% control %> loops to iterate DataObjectSets, that consist of DataObjects.
Applying this to pages: each page type consists of two classes: a data model (the Page class, an extended DataObject) and a controller (the Page_Controller class). The controller controls the Page template. Fortunately these page controllers have built-in access to the data within their Page Datamodel - including your custom methods it seems :-).
Controller methods like Menu() and Children() however return DataObjectSets of pages that can then be looped in a control structure - and that's just it: they are Page DataObjects and not Controllers. So within a control loop you have access to the Page class itself meaning methods defined the controller are not available. Same goes for custom methods that return things like DataObject::get('SiteTree',..) results. Remedy this by adding appropriate methods to the data model (Page) class...