3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1351 Views |
-
Simple short code example

6 December 2010 at 2:10pm
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.
-
Re: Simple short code example

6 December 2010 at 7:44pm
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.
| 1351 Views | ||
|
Page:
1
|
Go to Top |


