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:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

comparing a dataobject variable to a dataobject-holder variable

Go to End

2 Posts   1304 Views


Community Member, 24 Posts

6 November 2013 at 8:19pm

Edited: 06/11/2013 8:21pm

I am having a problem comparing a variable in a dataobject with a variable (one step up) in a productlisting page.

The variable in the product is called ProductCategory, and variable in the productlisting (or product holder) is called Category

I am actually using DataObjectAsPage module, but it is built on the dataobjectmanager.

function checkSomething(){
if ($this->ProductCategory != $Top.Category) {
return false;
} else {
return true;

then in the listing page I have <% if checkSomething %> which is inside the <% control %> loop for the products (on the product holder page)

Inside the control loop, in the .ss file I can print both these variables using $ProductCategory, $Top.Category
But not sure if Top is not working in the php file?
cant do an if statement right in the ss page, ss doesnt allow it?

Any help would be appreciated.


Community Member, 253 Posts

6 November 2013 at 9:05pm

Template variables (and notation) are not valid on the controller our model in the same way.

Instead of $Top.Category try $this->Category()

The category is likely available on your controller as it is