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, biapar, Willr, Ingo, swaiba, simon_w

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


6 Posts   1946 Views


30 March 2011 at 3:55am Community Member, 3 Posts

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.


30 March 2011 at 10:42am Forum Moderator, 1796 Posts

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


30 March 2011 at 6:14pm Forum Moderator, 5511 Posts

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


1 April 2011 at 2:10am Community Member, 3 Posts

The line:

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

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


18 August 2011 at 1:00am Community Member, 8 Posts

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


8 July 2014 at 8:33pm Community Member, 21 Posts

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