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.

All other Modules /

Discuss all other Modules here.

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

access to variables inside a control


Go to End


7 Posts   1546 Views

Avatar
wainui

Community Member, 56 Posts

18 May 2010 at 11:50am

Hi I am new to silverstripe and using the image gallery module..
I am tweaking the templates but cant seem to access the $AlbumTitle variable to put inside the GalleryItems control..

<h2>$AlbumTitle</h2>
<% control GalleryItems %>
// I want $AlbumTitle here :)
<% end_control %>

I have tried using Parent.. I must be missing something?

Mike

Avatar
3dgoo

Community Member, 135 Posts

18 May 2010 at 12:31pm

Try $Top.AlbumTitle

<% control GalleryItems %>
$Top.AlbumTitle
<% end_control %>

Avatar
wainui

Community Member, 56 Posts

18 May 2010 at 12:43pm

Yay :)

thank you so very much!

Avatar
Hamish

Community Member, 712 Posts

18 May 2010 at 12:45pm

You can't directly access the parent if there is not existing relationship (has been the subject of proposals that have never quite made it to the code, see http://open.silverstripe.org/ticket/4751).

However in this case you should be able to:

<h2>$AlbumTitle</h2> 
<% control GalleryItems %> 
$Album.AlbumTitle
<% end_control %>

Since ImageGalleryItem has an existing relationship to it's Album that you can traverse.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

18 May 2010 at 12:47pm

I don't think that's going to work because $Top will put you at the current controller, which is ImageGalleryPage.

Remember, ImageGalleryItem has a has_one 'Album', so keep it simple and use the relationship you're given

<% control GalleryItems %>
$Album.AlbumName
<% end_control %>

As a matter of good practice, you should never modify core templates. You should override them in your theme dir. By modding the core code, you're making upgrades very difficult!

Avatar
wainui

Community Member, 56 Posts

18 May 2010 at 6:52pm

oops..
i been hacking away very happily :)

It worked using $Top... I had to use top.top as was inside another controll (getting the hang of this :)

<div style="background:#fff; width:591px;">
<% control GalleryItems %>
<% if First %>
<div id="image" style="background:#fff; height:470px; ">
<span class=""></span>
<% control Image %>$CroppedImage(591, 394)<% end_control %>
<div style="color:#181818;">+ You are viewing: $Top.Top.AlbumTitle</div>
</div>
<% end_if %>
<% end_control %>

You should override them in your theme dir

Do I just add duplicates into the same folder my templates are in?

Avatar
wainui

Community Member, 56 Posts

18 May 2010 at 6:54pm

actually. both work.. $Album.AlbumName as well as $Top.AlbumName