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.

Template Questions /

$Link not being rendered


Reply


5 Posts   1866 Views

Avatar
J2-Paul

Community Member, 51 Posts

7 June 2010 at 9:45am

I have a problem using the $Link page control.

When I use the control outside a control loop all is fine it renders OK.

However, in side table the $Link is not rendering the href in the loop shows as /goedit?id=$ID instead of /student-search/goedit?id=$id.

Anyone see what I am doing wrong?

Thanks

--------------------------------------------------

      <% if StudentSearchResults %>
      
         <p>Total: $StudentSearchResults.Count
         $Link
         </p>
   
         <table width="99%">
            <thead>
               <tr>
                  <th></th>
                  <th>Student</th>
                  <th>ID</th>
               </tr>
            </thead>
            <tbody>
               <% control StudentSearchResults %>
                  <tr>
                     <td>$Link</td>
                     <td><a href="$Link/goedit?id=$ID">Edit</a></td>
                     <td>$FirstName $Lastname</td>
                     <td>$ID</td>
                  </tr>
               <% end_control %>
            </tbody>
         </table>

      <% end_if %>

Avatar
Pigeon

Community Member, 243 Posts

7 June 2010 at 10:11am

Hello again.

Because you are in the control loop for the student, SS thinks you are looking for the $Link property or method of the student. But you want the link of the page.

There are two options here, in your student class you can add a Link() method that will return the link:

function Link() {
return $this->CurrentPage()->Link() . 'goedit?id=' . $this->ID;
}


This will allow you to use just $Link in the control loop.

OR

you can get the current pages link in the template by proceeding the $Link with $Top like so:

...
<td><a href="$Top.Link/goedit?id=$ID">Edit</a></td>

You may have to surround the $Top.Link with curly brackets too: {$Top.Link}

I recommend the first method :)

Avatar
J2-Paul

Community Member, 51 Posts

10 June 2010 at 11:03am

Edited: 10/06/2010 11:19am

Thanks again. Dan, I have it working, but only using your least favourite option :-) I am afraid.

Firstly, when creating the method name "link()" the page never rendered, it just spinnered indefinitely. I then changed the method name to Pagelink() and the page rendered as per normal. I guess the word "link" must be a resevered/protected name for a method.?

Furthermore, the method returns an empty string. Any ideans?

...
      function Pagelink() {
      
         return $this->CurrentPage()->Link() . 'goedit?id=' . $this->ID;
      }

...
<% control StudentSearchResults %>
             <tr>
              <td><a href="{$Top.Link}goedit?id=$ID">Edit</a></td> <<< this one worked.
               <td><a href="{$Pagelink}goedit?id=$ID">Edit</a></td> <<< this one did not.
               <td>$FirstName $Lastname</td>
               <td>$ID</td>
            </tr>
    <% end_control %>

Avatar
Pigeon

Community Member, 243 Posts

10 June 2010 at 11:35am

That function looks fine. Make sure that it is a method of the object that you are controlling.

ie: Pagelink() has to be a function defined in the Student object (if the student object is being returned in the StudentSearchResults)

Also, you would only need to use $Pagelink in the template not {$Pagelink}editid=$ID

Tbh, if you can't get $Pagelink working, but $Top.Link/editid=$ID does, then use that.

Avatar
J2-Paul

Community Member, 51 Posts

10 June 2010 at 1:27pm

Dan. A penny has just dropped! I had the method in the wrong controller. Moved it to the student object and hey presto all is good.

Solving this one has also solved a few other queries too!

Thanks again Dan. !