Jump to:

23367 Posts in 18143 Topics by 2863 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: 1878 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
    1784 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
    5489 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.

  • HARVS1789UK
    Avatar
    Community Member
    19 Posts

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

    Thanks for pointing me in the right direction Willr

    This solution throws the following error in SS 3.1:

    PHP Fatal error: Cannot instantiate abstract class DBField in /var/www/sites/standard-bank/framework/control/injector/InjectionCreator.php on line 17

    So the solution for SS 3.1 seems to be to use the create_field() method instead i.e.

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

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