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.

Data Model Questions

Simple short code example


2 Posts   1747 Views


6 December 2010 at 2:10pm Community Member, 8 Posts

Can someone please provide a simple shortcodes example. I have created several text fields in my siteconfig, such as SiteTextURL, which stores the domain name of the site. In a template I know I can call, $Siteconfig.SiteTextURL, but this doesn't work inside tinyMCE's htmleditor field (for $content). I'd like to create a simple shortcode I can insert into tinyMCE whenever I want the value of SiteTextURL to be shown.

I reviewed the "Using Short Codes to embed a YouTube video" tutorial on SSBits, but it seems overtly complex.


6 December 2010 at 7:44pm Forum Moderator, 5511 Posts

The ssbits tutorial is quite good.

In your case ($SiteTextURL) you would do something like

// mysite/_config.php
ShortcodeParser::get('default')->register('SiteTextURL', array('Page', 'SiteTextURL'));

That line adds a ShortCode of [SiteTextURL] (1st argument) and the 2nd one says it calls the SiteTextURL function on the Page class. So lets define that function SiteTextURL on Page.

// mysite/code/Page.php

class Page extends SiteTree {
function SiteTextURL() {
return SiteConfig::current_site_config()->SiteTextURL;

And that should be all you need. Simply include [SiteTextURL] in the TinyMCE editor in the backend and it should be translated when you call $Content.