Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » $Link taking on the properties of nearest < %control %>

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2505 Views
  • Todd
    Avatar
    31 Posts

    $Link taking on the properties of nearest < %control %> Link to this post

    Hi,

    When I place the $Link variable in under the <% control ResizedImage(340,340) %> control, then $Link points to /assets/Uploads/ResizedImageblah.jpg. This make sense, however, I want the link to point to the subpages I created (<% control Children %>).

    How do I do this?

    <% control Children %>      
    <div class="left_sect">            
    <% control SectPic %>
       <% control ResizedImage(340,340) %>
          <a href="$Link">$Title</a>
           <img class="art_sect" src="$URL" alt="$Title" width="224" height="168" />
       <% end_control %>
    <% end_control %>
    </div>         
    <% end_control %>

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: $Link taking on the properties of nearest < %control %> Link to this post

    Why not put the link out of the image-control?

    Like this?

    <% control Children %>
    <div class="left_sect">
    <a href="$Link">$Title</a>
    <% control SectPic %>
    <% control ResizedImage(340,340) %>
    <img class="art_sect" src="$URL" alt="$Title" width="224" height="168" />
    <% end_control %>
    <% end_control %>
    </div>
    <% end_control %>

    You can also access outer controls with using $Top...
    see http://doc.silverstripe.com/doku.php?id=built-in-page-controls#dataobjectset_options

  • Todd
    Avatar
    31 Posts

    Re: $Link taking on the properties of nearest < %control %> Link to this post

    Hey Dio!

    What I really want to do is to link the resized images to their corresponding subpages like so:

    <a href="$Link"><img class="art_sect" src="$URL" alt="$Title" width="224" height="168" /></a>

    I just wanted to separate the two to make so as not to cause confusion.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: $Link taking on the properties of nearest < %control %> Link to this post

    Same thing,

    just put the control for the images in the link...

    <a href="$Link">
    <% control SectPic %>
    <% control ResizedImage(340,340) %>
    <img class="art_sect" src="$URL" alt="$Title" width="224" height="168" />
    <% end_control %>
    <% end_control %>
    </a>

    Or even:

    <a href="$Link"><img class="art_sect" src="<% control SectPic %><% control ResizedImage(340,340) %>$URL<% end_control %><% end_control %>" /></a>

    or something like that...

  • Todd
    Avatar
    31 Posts

    Re: $Link taking on the properties of nearest < %control %> Link to this post

    Thanks!

    Both worked great.

    Todd

  • iadawn
    Avatar
    Community Member
    13 Posts

    Re: $Link taking on the properties of nearest < %control %> Link to this post

    Of course if one wants to do something like this:

    <ul>
    <% control LatestIssues %>
    <li><a href="$Link/view/$ID">$Title</a></li>
    <% end_control %>

    One runs into the problem again. So how does one refer to parameters within the structures surrounding the current control.

    Would be useful to do something like: $Page.Link, or if in a nested control structure, something like ControlStructure.Title e.g. $LatestIssues.Title. This would allow for nesting of control structures with full access to surrounding parameters.

    Kevin

    P.s. Since $Page.Link doesn't work I will be embedding the Link into the control structure within the controller.

  • dio5
    Avatar
    Community Member
    501 Posts
  • iadawn
    Avatar
    Community Member
    13 Posts

    Re: $Link taking on the properties of nearest < %control %> Link to this post

    Well that worked.... now where in the docs did you find that?

    Cheers

    Kevin

    2505 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.