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.


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

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

Virtual Properties


8 Posts   1501 Views


21 January 2008 at 3:10pm Community Member, 94 Posts

I was reading this page here: [url][/url] which said that you can make your own virtual properties.

What I want to do is very similar to what they have listed. They take the firstname and surname and then return it as a title.

My question is, how do you then refer to that virtual property in the .ss template (which I am assuming you can)? $getTitle?

Does the code getTitle() go in the Page or in the Controller?


21 January 2008 at 4:26pm Community Member, 94 Posts

OK I worked it out. It works well in the Controller, and I just use the function name in the template. eg. $getTitle.

However, say you want to do a small string manipulation within that last function, eg, strip all whitespace, where should this new function exist? In the controller alongside getTitle()?


21 January 2008 at 5:26pm Community Member, 94 Posts

It is as though once I have worked out the exact wording to communicate what I want to ask, the answer comes to me in about half an hour.

Thank you!!

I placed the new function in the controller and referred to it like $this->functionName() and it worked a treat.

Thank you again! :)


21 January 2008 at 10:16pm Community Member, 501 Posts

It works equally well in the 'model' or 'page' or 'object' and I think most of the time is even better there.

Functions you define in the controller also get called as an action as part of an url.
( urlsegment/action/id/ ).

When you have something like firstName and surname, and you want to return it as a title,
I think it might be better to define it on the object model, rather than in the controller.

just put something like

function FullName()
return $this->FirstName ." ". $this->Surname;

on the eg. Page class (not controller) , and it will work as $FullName in the template.


22 January 2008 at 12:50pm Community Member, 94 Posts

So functions defined in the controller can refer to functions defined in the page class, and referenced as though they were defined in the controller? So for example: $this->function() ?

So far so good.


22 January 2008 at 1:06pm Community Member, 501 Posts

Euhm.. :-) probably yes, but most of the time you'll probably won't be needing them in the controller.. Just define them on your 'Page' (or whatever) class and access them in the template.

Hard to see without knowing what you're doing. :-)

I wouldn't put getTitle() like in yr example in the controller class, but in the 'Page' class.


22 January 2008 at 1:38pm Community Member, 94 Posts

Have shifted it all over to the Page class*. So far, so good. :)

So then what does belong in the controller class?

Also, if a child has a defined virtual property, can it be referred to by a parent, in the template?

<% control Children %> $child.subproperty <% end_control %>


*Not the actual page class but the one I have extended. eg. ArticlePage.


22 January 2008 at 1:45pm Community Member, 94 Posts


My bad. The virtual property is referred to in the template, as though it were a normal property, and it works all good.

Thank you!:)