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   424 Views

Avatar
MrNick

6 March 2012 at 11:06pm Community Member, 9 Posts

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

7 March 2012 at 8:18am Community Member, 115 Posts

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

7 March 2012 at 7:23pm Forum Moderator, 5511 Posts

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

Avatar
MrNick

8 March 2012 at 7:35am Community Member, 9 Posts

Thanks Willr :) Excellent.