Jump to:

23550 Posts in 19336 Topics by 2890 members

General Questions

SilverStripe Forums » General Questions » Add custom function to .ss template

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

Page: 1
Go to End
Author Topic: 1658 Views
  • DeklinKelly
    Community Member
    197 Posts

    Add custom function to .ss template Link to this post

    How can I add a custom function to my template?

    This gives me an error: Parse error: syntax error, unexpected $end

    // PortfolioIndex.php
    class PortfolioIndex extends Page {
    static $db = array(
    'Heading' => 'Text'

    static $has_one = array(

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Content", new TextField('Heading','Heading'));
    return $fields;

    class PortfolioIndex_Controller extends Page_Controller {
       function CustomStuff () {
          return '<h1>CustomStuff</h1>';

    And here is my template (PortfolioIndex.ss) :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <% base_tag %>
    <% control CustomStuff %>

  • Aram
    Community Member
    598 Posts

    Re: Add custom function to .ss template Link to this post

    Hi Hkight

    Because your function returns a string you need to use the $FunctionName in your template not a <% control %> block which is for returning DataObjectSets (e.g. sets of pages).

    So you just need to call $CustomStuff and it will place the returned value into your template

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.