Jump to:

23477 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Passing an ID value to a function

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

Page: 1
Go to End
Author Topic: 213 Views
  • hano
    Community Member
    1 Post

    Passing an ID value to a function Link to this post

    I want to achieve a seemingly simple task, however I have been searching the web and the forums here to no avail for more than a week
    My problem is this

    I have enabled search form in a silverstripe website and have managed to successfully implement the search of dataobjects on the site.

    However when the DataObjects(Products), are displayed in the search results I want to be able to link them to the category pages that they belong to. To achieve this I wrote a simple function in the page controller, that will return the category page based on the ID provided.

    public function getCategoryPages($theID) {
       return SiteTree::get()->filter('ID',$theID);

    and I wanted to be able to do this in the template

    <% loop $Results %>

                   <% if CategoryID %>
                   <% loop $Top.getCategoryPages($CategoryID) %>
                      <a href="$Link">Link</a>
                   <% end_loop %>
                   <% end_if %>
    <% end_loop %>

    The problem is no matter what I do I am not able to pass the correct $CategoryID value to the function. I have tried, almost everything but I am not able to do so, please someone point me in the right direction, it was my understanding that this is possible to do in SilverStripe 3.0 which is the version I am using. I am I trying to do something that is not possible? If so how can I get around this problem? Any help would be greatly appreciated (I have pulled all of my hair out trying to figure this out )

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.