Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » accesing to sitetree link from template

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

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

Page: 1
Go to End
Author Topic: 3291 Views
  • nomen
    Avatar
    Community Member
    52 Posts

    accesing to sitetree link from template Link to this post

    Hello:

    I defined a new page. This page includes a link to another sitetree page.

       static $has_one = array
          (
             "LinkTo" => "SiteTree",
          );          


    The user can create the link in the CMS without problems because in getCMSFields i have

             $fields->addFieldToTab("Root.Content.Main", new TreeDropdownField('LinkToID', "Link", "SiteTree"),'Content');   

    The problem comes with the template usage.
    I can access to LinkToID value without problem. It returns a numeric value (for example 5).
    But i´m not interested in the ID. I´m interested in his URL: for example, the link with the ID 5 is "http://www.mysite.com/who-we-are".
    How can i obtain this link?
    Another question is, if i have a multilanguage site, this link will be correct with the current language of the site?

    Thanks in advance, and excuse me for my poor english.

  • cevic
    Avatar
    Community Member
    5 Posts

    Re: accesing to sitetree link from template Link to this post

    I'm trying to solve a problem similar to your (see my post http://www.silverstripe.com/site-builders-forum/flat/45018). Have you found a way around?

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: accesing to sitetree link from template Link to this post

    There's probably some internal function for this ,but I could not find it as well...
    A workaround is creating a method on your class which gets and returns the page..

    Something like this :

    function get_Hyperlink_URLSegment() {
          $oTmpDataObject = DataObject::get_by_id("Page",$this->iSiteTreeID);
          return $oTmpDataObject->URLSegment;
    }

  • Shane Garelja
    Avatar
    Community Member
    18 Posts

    Re: accesing to sitetree link from template Link to this post

    @nomen - you would access it like this in your template:

    <a href="$LinkTo.Link">Link to my page</a>

    ... as "LinkTo" is the relationship name (as defined in your has_one array) for the Page object that you've linked to (or saved). "LinkToID" is just the foreign key column hence you only get an integer.

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