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.

General Questions /

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

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

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

Go to End

6 Posts   3452 Views


Community Member, 3 Posts

30 March 2011 at 3:55am

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.


Forum Moderator, 1899 Posts

30 March 2011 at 10:42am

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


Forum Moderator, 5523 Posts

30 March 2011 at 6:14pm

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);


Community Member, 3 Posts

1 April 2011 at 2:10am

The line:

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

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


Community Member, 8 Posts

18 August 2011 at 1:00am

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


Community Member, 31 Posts

8 July 2014 at 8:33pm

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);