.. include:: /Includes.rst.txt .. _cobj-user: .. _cobj-user-int: ================== USER and USER\_INT ================== This calls either a PHP function or a method in a class. This is very useful if you want to incorporate your own data processing or content. Basically USER and USER\_INT are user defined cObjects, because they just call a function or method, which you control! If you call a method in a class (which is of course instantiated as an object), the internal variable :php:`$cObj` of that class is set with a *reference* to the parent cObject. This offers you an API of functions, which might be more or less relevant for you. See :file:`ContentObjectRenderer.php` in the TYPO3 source code; access to :typoscript:`typolink` or :typoscript:`stdWrap` are only two of the gimmicks you get. If you create this object as :typoscript:`USER_INT`, it will be rendered non-cached, outside the main page-rendering. userFunc ======== .. ### BEGIN~OF~TABLE ### .. container:: table-row Property userFunc Data type :ref:`data-type-function-name` Description The name of the function, which should be called. If you specify the name with a '->' in it, then it is interpreted as a call to a method in a class. Two parameters are sent to the PHP function: First a content variable (which is empty for USER/USER\_INT objects, but not when the user function is called from stdWrap functions .postUserFunc or .preUserFunc). The second parameter is an array with the properties of this cObject, if any. .. ###### END~OF~TABLE ###### (properties you define) ======================= .. ### BEGIN~OF~TABLE ### .. container:: table-row Property (properties you define) Data type (the data type you want) Description Apart from the properties "userFunc" and "stdWrap", which are defined for all USER/USER\_INT objects by default, you can add additional properties with any name and any data type to your USER/USER\_INT object. These properties and their values will then be available in PHP; they will be passed to your function (in the second parameter). This allows you to process them further in any way you wish. .. ###### END~OF~TABLE ###### stdWrap ======= .. ### BEGIN~OF~TABLE ### .. container:: table-row Property stdWrap Data type Everything that's made available by :ref:`stdWrap`. .. ###### END~OF~TABLE ###### cache ===== .. ### BEGIN~OF~TABLE ### .. include:: ../../DataTypes/Properties/Cache.rst.txt .. ###### END~OF~TABLE ###### .. _cobj-user-examples: .. _cobj-user-int-examples: Examples ======== .. attention:: For the best result you should *always*, without exception, place your class files in an extension, define composer class loading for this extension and add this extension as a dependency of your project. Then, your classes will load without issues when you refer to them by their class name. Example 1 --------- This example shows how to include your own PHP script and how to use it from TypoScript. Use this TypoScript configuration:: page = PAGE page.10 = USER_INT page.10 { userFunc = Vendor\ExtensionName\ExampleTime->printTime } The file typo3conf/ext/extension_name/Classes/ExampleTime.php might amongst other things contain: .. code-block:: php namespace Vendor\ExtensionName; class ExampleTime { /** * Output the current time in red letters * * @param string Empty string (no content to process) * @param array TypoScript configuration * @return string HTML output, showing the current server time. */ public function printTime(string $content, array $conf): string { return '
Dynamic time: ' . date('H:i:s') . '