Jump to:

22975 Posts in 11620 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » How to convert URLs from /extending-silverstripe-overview/ to correct form?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1731 Views
  • fradario
    Avatar
    Community Member
    3 Posts

    How to convert URLs from [sitetree_link id=17] to correct form? Link to this post

    Hi to all

    I have a function in my controller class that returns html text containig URL like [sitetree_link id=17].
    When I call that function from a template file ".ss" the URL still remain of the form [sitetree_link id=17] and don't get converted in the correct form.

    Is there something to do to get URLs converted as usual?

    Thank you.

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: How to convert URLs from [sitetree_link id=17] to correct form? Link to this post

    hmmm I've seen this in an old version of silverstripe when I create links in the tinymce, but I'm confused as to why you'd return this from a controller function. Surely you'd return $page->Link() and that would be an actually url?

    I may have misunderstood, so it might help if you post the controller function code...

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: How to convert URLs from [sitetree_link id=17] to correct form? Link to this post

    The [sitetee_link] is a ShortCode. By default ShortCodes are parsed when you output HTMLText fields to your template. If you are altering your HTMLTextField in your controller, make sure you return the result as an HTMLText field

    // This code will FAIL - show [sitetree..]
    function Foo() {
    return $this->Content;
    }

    // This code will WORK - translate showcodes
    function Foo() {
    return DBField::create('HTMLText', $this->Content);
    }

  • fradario
    Avatar
    Community Member
    3 Posts

    Re: How to convert URLs from [sitetree_link id=17] to correct form? Link to this post

    The line:

    return DBField::create('HTMLText', $this->Content);

    is what I was looking for, thank Willr and Swaiba for the answers.

  • qbahamutp
    Avatar
    Community Member
    8 Posts

    Re: How to convert URLs from [sitetree_link id=17] to correct form? Link to this post

    I'll second that. Thanks Willr - you just saved me from what otherwise may have been hours of frustration. +1 kudo's.

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