Templates ========= .. sectionauthor:: Bernhard Posselt OC_Template ----------- .. php:class:: OC_Template This class provides the templates for owncloud. It is used for loading template files, assign variables to it and render the whole template. .. php:method:: __construct($app, $name[, $renderas]) :param string $app: the name of the app :param string $file: name of the template file (without suffix) :param string $renderas: If $renderas is set, OC_Template will try to produce a full page in the according layout. For now, renderas can be set to "guest", "user" or "admin" :returns: OC_Template object **Example:** .. code-block:: php .. php:method:: addHeader($tag, $attributes[, $text='']) :param string $tag: tag name of the element :param array $attributes: array of attrobutes for the element :param string $text: the text content for the element Add a custom element to the html **Example:** .. code-block:: php addHeader('title', array(), 'My new Page'); ?> .. php:method:: append($key, $value) :param string $key: the key under which the variable can be accessed in the template :param $value: the value that we want to pass :returns: bool This function assigns a variable in an array context. If the key already exists, the value will be appended. It can be accessed via $_[$key][$position] in the template. **Example:** .. code-block:: php assign('customers', $customers); $mainTemplate->append('customers', 'hanna'); ?> .. php:method:: assign($key, $value[, $sanitizeHTML=true]) :param string $key: the key under which the variable can be accessed in the template :param $value: the value that we want to pass :param bool $sanitizeHTML: false, if data shouldn't get passed through htmlentities :returns: bool This function assigns a variable. It can be accessed via $_[$key] in the template. If the key existed before, it will be overwritten **Example:** .. code-block:: php assign('customers', $customers); ?> .. php:method:: detectFormfactor() :returns: The mode of the client as a string. **default** -> the normal desktop browser interface, **mobile** -> interface for smartphones, **tablet** -> interface for tablets, **standalone** -> the default interface but without header, footer and sidebar, just the application. Useful to use just a specific app on the desktop in a standalone window. **Example:** .. code-block:: php detectFormfactor(); ?> .. php:method:: fetchPage() :returns: the HTML of the template as string This function proceeds the template and but prints no output. **Example:** .. todo:: provide example .. php:method:: getFormFactorExtension() :returns: Returns the formfactor extension for current formfactor (like .mobile or .tablet) **Example:** .. code-block:: php detectFormfactorExtension(); ?> .. php:method:: inc($file[, $additionalparams]) :param string $file: the name of the template :param array $additionalparams: an array with additional variables which should be used for the included template :returns: returns content of included template as a string Includes another template. use inc('template')); ?> to do this. The included template has access to all parent template variables! **Example:** .. code-block:: php
inc('nav.inc', array('active' => 'nav_entry_1')); ?>
.. php:method:: printPage() :returns: true when there is content to print This function proceeds the template and prints its output. **Example:** .. code-block:: php assign('test', array("test", "test2")); $mainTemplate->printPage(); ?> .. php:method:: printAdminPage($application, $name[, $parameters]) :param string $application: The application we render the template for :param string $name: Name of the template :param array $parameters: Parameters for the template :returns: bool Shortcut to print a simple page for admin **Example:** .. todo:: provide example .. php:method:: printGuestPage($application, $name[, $parameters]) :param string $application: The application we render the template for :param string $name: Name of the template :param array $parameters: Parameters for the template :returns: bool Shortcut to print a simple page for guests **Example:** .. todo:: provide example .. php:method:: printUserPage($application, $name[, $parameters]) :param string $application: The application we render the template for :param string $name: Name of the template :param array $parameters: Parameters for the template :returns: bool Shortcut to print a simple page for users **Example:** .. todo:: provide example Template functions ------------------ These functions are automatically available in all templates. html_select_options ~~~~~~~~~~~~~~~~~~~ .. php:function:: html_select_options($options, $selected[, $params]) :param array $options: an array of the form value => label :param string/array $selected: an array containing strings or a simple string which sets a value as selected :param array $params: optional parameters that are done in key => value :returns: the html as string of preset