Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Using Variables in Controls... I think

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

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

Page: 1
Go to End
Author Topic: 1176 Views
  • Alex S
    Avatar
    Community Member
    30 Posts

    Using Variables in Controls... I think Link to this post

    Hey, this might be a dumb question, but...

    I've just finished tutorial 2 and thought I'd extend the news on the homepage functionality to check that I'd understood everything. I added a check box which determines if the news shows, and a number to define how many news items show. The check box works fine and the number is stored correctly, I can view it on the page using the variable '$NumTopNews'. So far I've tried to use the '$NumTopNews' variable as an argument to the 'LatestNews' function, without any luck. E.g.

    ...
    <% control LatestNews($NumTopNews) %>
    ...

    My guess is that this means it should go into the controller, and the number be written directly into the 'LatestNews' function, trouble is, I'm not really sure how to do that.

    Could someone give me a nudge in the right direction?

    Cheers,

    Alex

  • Alex S
    Avatar
    Community Member
    30 Posts

    Re: Using Variables in Controls... I think Link to this post

    Yup, I was being dumb, turns out it was the controller that needed to be changed:

    ...
    function LatestNews() {
          $news = DataObject::get_one("ArticleHolder");
          return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $this->NumTopNews) : false;
       }
    ...

    Works great

    Nice CMS by the way.

    Alex

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Using Variables in Controls... I think Link to this post

    As you probably realised with <% control LatestNews($NumTopNews) %> you cant use variables as parameters to methods, its a limitation of the template syntax so you can do <% control LatestNews(10) %> rather then $NumTopNews

    1176 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.