Jump to:

3445 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » External link from the template

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

Page: 1
Go to End
Author Topic: 795 Views
  • Bolixe
    Avatar
    Community Member
    17 Posts

    External link from the template Link to this post

    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

  • mishell
    Avatar
    Community Member
    19 Posts

    Re: External link from the template Link to this post

    one way is:

    class Item extends DataObject {

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

    }

    in template use

    $ItemURL

  • Bolixe
    Avatar
    Community Member
    17 Posts

    Re: External link from the template Link to this post

    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

  • Bolixe
    Avatar
    Community Member
    17 Posts

    Re: External link from the template Link to this post

    Hehehe, it is done! Problem solved

    Thnx again!!

  • sajok
    Avatar
    Community Member
    82 Posts

    Re: External link from the template Link to this post

    Can you share the solution you found. thanx

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