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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

access page.php function inside menu loop


Go to End


4 Posts   2946 Views

Avatar
pbenoit

Community Member, 9 Posts

1 December 2012 at 6:49am

Hi all,

I have a menu loop and im struggling to get a function I need to run within it.

I have the functions on my page.php file so it should be accessed by all pages. Calling the function is ok in the nav include outside the menu loop but not inside.

Basiclly im trying to show a share price value from an XML file inside a dropdown nav. Any ideas??

<ul class="nav_pri">
<% loop Menu(1) %>
<li class="$LinkingMode">
code
<% if Children %>
code
<% if $MenuTitle="Investors" %>
access function from page.php $sahre_price
<% else %>
show something else
<% end_if %>
code
<% end_if %>
code
<% end_loop %>
</ul>

Avatar
Willr

Forum Moderator, 5523 Posts

2 December 2012 at 5:22pm

I have the functions on my page.php file so it should be accessed by all pages. Calling the function is ok in the nav include outside the menu loop but not inside.

Make sure the function is inside the Page class part of the file. SilverStripe won't pick up anything outside of the page class in this context, and if it's in the controller class in that file you'll only see it on the top level.

Avatar
pbenoit

Community Member, 9 Posts

5 December 2012 at 12:35am

Thanks Willr,

Adding this seems to have caused an issue with the site, instead of looking for 'pageType_live' in query strings it's now using 'pageType' only.

This caused some large issues with our server and crashed everything.

Any ideas?

Phil

Avatar
Willr

Forum Moderator, 5523 Posts

5 December 2012 at 6:30pm

This sounds like more an issue with what your code does rather than where. Post it here and people may be able to suggest fixes.