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.

General Questions /

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

Accessing a controller method in template, when in control loop


Reply


4 Posts   511 Views

Avatar
MrNick

Community Member, 9 Posts

6 March 2012 at 11:06pm

Hello,

In my controller I have a function which I want to call in my template.

This works fine, however when I am in a control loop eg,
<% control articles %>
<p>$Name</p> :) $MyControllerFunction
<% end_control %>

It outputs $Name fine, but fails on $MyControllerFunction as it seems to be trying to access a method/property on the article.

How can I get the controller function?

Avatar
novaweb

Community Member, 115 Posts

7 March 2012 at 8:18am

Hey MrNick,

Please post your function to http://www.pastie.org and let me know what data you're trying to access from your function.

Cheers,
Josh

Avatar
Willr

Forum Moderator, 5513 Posts

7 March 2012 at 7:23pm

You have to use $Top to call the topmost controller, $Top.MyControllerFunction.

Avatar
MrNick

Community Member, 9 Posts

8 March 2012 at 7:35am

Thanks Willr :) Excellent.