Jump to:

10849 Posts in 2516 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » access to variables inside a control

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1013 Views
  • wainui
    Avatar
    Community Member
    56 Posts

    access to variables inside a control Link to this post

    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

  • ampedup
    Avatar
    Community Member
    133 Posts

    Re: access to variables inside a control Link to this post

    Try $Top.AlbumTitle

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

  • wainui
    Avatar
    Community Member
    56 Posts

    Re: access to variables inside a control Link to this post

    Yay

    thank you so very much!

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: access to variables inside a control Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: access to variables inside a control Link to this post

    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!

  • wainui
    Avatar
    Community Member
    56 Posts

    Re: access to variables inside a control Link to this post

    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?

  • wainui
    Avatar
    Community Member
    56 Posts

    Re: access to variables inside a control Link to this post

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

    1013 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.