Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Simple short code example

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

Page: 1
Go to End
Author Topic: 1730 Views
  • WebSiteGuy
    Community Member
    8 Posts

    Simple short code example Link to this post

    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.

  • Willr
    Forum Moderator
    5508 Posts

    Re: Simple short code example Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.