TYPO3: Writing user function

This example shows how we can get the result of user function to an object. Write the following typoscript to call the user function

Including the file.

includeLibs.getpagecontent = EXT:extname/Classes/UserFunc/PageContent.php

getpagecontent : Variable to include the file.
extname : Extension name
PageContent.php : File name which contains the class for user function.

Enabling the user function

lib.subcontent = USER
lib.subcontent {
userFunc = tx_user_pagecontent->getSubPageContents
page_id.cObject < temp.pageIds
exclude_pid = 1

lib.subcontent: Typo3 Object
tx_user_pagecontent : Class name in the file 'PageContent.php'
getSubPageContents : Function name which return the result
page_id, exclude_pid: Parameter that is sent to the function

Now add the file called "PageContent.php" in your extension called "extname" at the path extname/Classes/UserFunc/
PageContent.php file looks like the following structure.

class tx_user_pagecontent {
* Reference to the parent (calling) cObject set from TypoScript
public $cObj;
* @param array TypoScript configuration
* @return string HTML output, showing content elements
   public function getSubPageContents($content, $conf) {
     Some calculations...
     return $result;

Now the value of $result is assigned to the object "lib.subcontent".
The value of the result can be any thing like variable, integer, HTML content, string etc..