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

Workaround accessing $Top scope in includes


Go to End


3 Posts   2778 Views

Avatar
abes

Community Member, 11 Posts

2 September 2014 at 8:02am

Edited: 02/09/2014 8:08am

I just learned, that the $Top scope of an template isn't available within includes, because the $Top scope is set to the current scope of the including template. This can be looked up here:
https://github.com/silverstripe/silverstripe-framework/issues/3460

In the docs this behaviour is described as follows:
"Includes can't directly access the parent scope"
http://doc.silverstripe.org/framework/en/reference/templates

Because I thought this is quite mistakable, I wrote a comment clarifying this in the help pages. And as I think it is quite normal to need the "original" $Top scope within includes I posted a little workaround for this:
MainTemplate: <% include NestedTemplate MainController=$Top %>
NestedTemplate: <% include NestedTemplate MainController=$MainController %>

But my comment didn't last 10 minutes before it disappeared. I don't know if it has been deleted or if there's another reason why it is not available anymore. I didn't get any feedback.

Therefor some questions:
- Why my comment did disappear?
- When it has been deleted: Why? And why I got no feedback / response?
- Is something wrong with my workaround, because of which it should not appear on the help pages? And if: Would it not be better to inform the author about such mistakes and not only deleting the comment? Or to correct it answering the comment so others can learn from it?

Avatar
Willr

Forum Moderator, 5523 Posts

4 September 2014 at 9:35pm

1) All comments are moderated. Your comment would have gone into the queue and it's been approved now.
2) You should have got a email when it was approved. If not, double check your email settings in DIsqus
3) Your solution is correct and is the recommended way to approach it.

Avatar
abes

Community Member, 11 Posts

7 September 2014 at 11:01pm

Thx Willr for this enlightenment.

From my point of view it looked like my comment was published and then - some minutes later - by moderation deleted or whatever. Therefor I didn't expect, it is just in a moderation queue.

Perhaps there should be a additional remark mentioning that comments are hidden until they are released by moderators.