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

Using Variables in Controls... I think


3 Posts   1189 Views

Alex S

9 September 2008 at 6:25am Community Member, 30 Posts

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?



Alex S

9 September 2008 at 6:48am Community Member, 30 Posts

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.



9 September 2008 at 9:42am Forum Moderator, 5511 Posts

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