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.

All other Modules

Discuss all other Modules here.

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

access to variables inside a control


Reply

7 Posts   1059 Views

Avatar
wainui

18 May 2010 at 11:50am Community Member, 56 Posts

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

18 May 2010 at 12:31pm Community Member, 133 Posts

Try $Top.AlbumTitle

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

Avatar
wainui

18 May 2010 at 12:43pm Community Member, 56 Posts

Yay :)

thank you so very much!

Avatar
Hamish

18 May 2010 at 12:45pm Community Member, 712 Posts

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 [url]http://open.silverstripe.org/ticket/4751[/url]).

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

18 May 2010 at 12:47pm 4085 Posts

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

18 May 2010 at 6:52pm Community Member, 56 Posts

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

18 May 2010 at 6:54pm Community Member, 56 Posts

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