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 /

External link from the template


Reply


5 Posts   830 Views

Avatar
Bolixe

Community Member, 17 Posts

23 February 2012 at 3:43am

Hi all!!

I know it should be simple, but since I am into silverstripe some months ago I have sometimes problem with smallest things.

I am trying to generate in my template one picture with a link to external site. This link will be written by my customer when he makes and entry in the cms, so will come from DB. The problem is, the link is coming right, but the finall result is link with the baseurl in the href that look like this "http://mydomain/parentpage/http://www.google.es".

The code in the template is:

<div class="typography">
   <ul>
    <% control Items %>
       <h2>$Title</h2>
<p><a target="_blank" href="http//www.$ExternalLink/" rel="external">$Photo.SetWidth(50)</a></p>
         <li>
            <p>$Content.FirstParagraph</p>
            <a href="$Link">View</a>
         </li>
      <% end_control %>
   </ul>
</div>

$ExternalLink is a text type in DB

Thanks Greetings

Avatar
mishell

Community Member, 19 Posts

28 February 2012 at 9:36am

one way is:

class Item extends DataObject {

public function getItemURL() {
return 'http://blablabla/'.$this->ExternalLink;
}

}

in template use

$ItemURL

Avatar
Bolixe

Community Member, 17 Posts

20 April 2012 at 12:20am

Hi mishell,

sorry I had left this project for a moment to focus on anothers. I forgot totally about my post.

I am trying your solution, but it doesn´t work, the issue I think is different, how SS handle the template and treats the <a href> tags. Because the $ExternalLink is showing right if I place it in h2 for example.

I mean if I even use static word for example:

<a href="Hellloworld" rel="external">linkName</a>

SS is adding the baseUrl before Helloworld when build the template, so the final:

href --> 'http//www.baseurl.com/dataObject/Helloworld'

What I want to get is href --> 'Helloworld' only to then I build my link on my own.

Thanks for your reply, bye

Avatar
Bolixe

Community Member, 17 Posts

20 April 2012 at 12:53am

Hehehe, it is done! Problem solved

Thnx again!!

Avatar
sajok

Community Member, 82 Posts

22 July 2012 at 3:27am

Can you share the solution you found. thanx