10389 Posts in 2200 Topics by 1712 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 890 Views |
-
access to variables inside a control

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
-
Re: access to variables inside a control

18 May 2010 at 12:31pm
Try $Top.AlbumTitle
<% control GalleryItems %>
$Top.AlbumTitle
<% end_control %> -
Re: access to variables inside a control

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.
-
Re: access to variables inside a control

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!
-
Re: access to variables inside a control

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?
-
Re: access to variables inside a control

18 May 2010 at 6:54pm
actually. both work.. $Album.AlbumName as well as $Top.AlbumName
| 890 Views | ||
|
Page:
1
|
Go to Top |



