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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Custom Variables in Content - as shortcodes do not nest


Go to End


937 Views

Avatar
tuxibear

Community Member, 9 Posts

7 July 2016 at 3:11am

I found this topic which does work for text,

http://www.silverstripe.org/community/forums/customising-the-cms/show/23600

which gave this code

 if($this->Content) {
$hasLocation = stristr($this->Content, '$MyVariable');

if($hasLocation) {
$content = str_ireplace('$MyVariable', $value, $this->Content);
return array(
'Content' => DBField::create_field('HTMLText', $content),
);
}
}

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

Which does work.

My Question is, can this be repurposed to inject HTML code instead of text? I want to be able to make shortcodes for a tabbed area of content, but the shortcodes don't nest so that's not an option.

Thoughts?