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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Add custom function to .ss template

Go to End

2 Posts   2504 Views


Community Member, 197 Posts

13 May 2009 at 10:00pm

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 ( :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
<% base_tag %>
<% control CustomStuff %>

Carbon Crayon

Community Member, 598 Posts

13 May 2009 at 10:04pm

Edited: 13/05/2009 10:04pm

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 :)