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.

Archive /

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

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

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


Reply


8 Posts   2627 Views

Avatar
Todd

31 Posts

7 May 2008 at 6:29am

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 %>

Avatar
dio5

Community Member, 501 Posts

7 May 2008 at 7:44am

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

Avatar
Todd

31 Posts

7 May 2008 at 10:09am

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.

Avatar
dio5

Community Member, 501 Posts

7 May 2008 at 10:22am

Edited: 07/05/2008 10:23am

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

Avatar
Todd

31 Posts

7 May 2008 at 10:44am

Thanks!

Both worked great.

Todd

Avatar
iadawn

Community Member, 13 Posts

13 October 2008 at 9:57pm

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.

Avatar
dio5

Community Member, 501 Posts

13 October 2008 at 10:01pm

$Top.Link?

Avatar
iadawn

Community Member, 13 Posts

13 October 2008 at 10:37pm

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

Cheers

Kevin