title: Silverstripe 3.1: Link to page of data object from inside loop
body: <p>I'm trying to link an image to the page it belongs to from a control loop on a separate page.</p>
  
  <p>I have a controller function which grabs all of a certain page type which can be used on other pages to show their content.
  I call those pages and loop their children and then the images on those children.</p>
  
  <p>The image link should refer to the child page which has the images. Currently $Link will only show the link to the image itself and $Top.Link refers to the current page not the page that contains the images.</p>
  
  <p>Is there something I can use in the template or do I need another function?</p>
  
  <pre><code>&lt;% loop $MyPages(A) %&gt;
   &lt;% loop $Children(B) %&gt;
    &lt;% loop $MyImages(C) %&gt;
      &lt;a href="$LinkToChildPage(B)"&gt;&lt;img src="$URL"&gt;&lt;/a&gt;
    &lt;% end_loop %&gt;
   &lt;% end_loop %&gt;
  &lt;% end_loop %&gt;
  </code></pre>