Jump to:

7938 Posts in 1541 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » comparing a dataobject variable to a dataobject-holder variable

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 447 Views
  • bit99
    Avatar
    Community Member
    24 Posts

    comparing a dataobject variable to a dataobject-holder variable Link to this post

    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.
    Thanks,

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: comparing a dataobject variable to a dataobject-holder variable Link to this post

    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

    447 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.