diff --git a/developer_manual/templates.rst b/developer_manual/templates.rst index 142b55525..01fb8f2bc 100644 --- a/developer_manual/templates.rst +++ b/developer_manual/templates.rst @@ -2,57 +2,6 @@ Templates ========= .. sectionauthor:: Bernhard Posselt -.. warning:: - .. versionchanged:: 5.0 - - To prevent XSS the following PHP **functions for printing are forbidden: echo, print() and assign($key, $value)``. - - -ownCloud uses its own templating system. Templates reside in the ``template/`` folder. To use them you'll need to instantiate the ``OC_Template`` class with the name of the template. If you want to pass values to it, use the ``assign`` method. - - -:file:`index.php` - -.. code-block:: php - - assign('entries', $allEntries); - $mainTemplate->assign('name', "john doe"); - $mainTemplate->printPage(); - ?> - -To access the assigned variables in the template, use the $_[] array. The variable will be availabe under the key that you defined (e.g. $_['key']). - -:file:`templates/main.php` - -.. code-block:: php - - -

- inc('sub.inc')); - - ?> - -Templates can also include other templates by using the $this->inc('templateName') method. Use this if you find yourself repeating a lot of the same HTML constructs. The parent variables will also be available in the included templates, but should you require it, you can also pass new variables to it by using the second optional parameter for $this->inc. - -:file:`templates/sub.inc.php` - -.. code-block:: php - -
I am included but i can still access the parents variables!
- - - - OC_Template ----------- diff --git a/developer_manual/tutorial.rst b/developer_manual/tutorial.rst index cfdc02441..6815ef072 100644 --- a/developer_manual/tutorial.rst +++ b/developer_manual/tutorial.rst @@ -376,7 +376,44 @@ This will allow you to easily mock the API in your unittests. Templates --------- -Templates reside in the **template/** folder. To use them in your controller, use the TemplateResponse class, for instance +ownCloud uses its own templating system. Templates reside in the **template/** folder. In every template file you can easily access the template functions listed in :doc:`templates` + +.. note:: + Templates **must not contain database queries**! All data should be passed to the template via ``$template->assign($key, $value)``. + + +To access the assigned variables in the template, use the **$_[]** array. The variable will be availabe under the key that you defined (e.g. $_['key']). + +:file:`templates/main.php` + +.. code-block:: php + + +

+ inc('sub.inc')); + + ?> + +.. warning:: + .. versionchanged:: 5.0 + + To prevent XSS the following PHP **functions for printing are forbidden: echo, print() and inc('templateName')** method. Use this if you find yourself repeating a lot of the same HTML constructs. The parent variables will also be available in the included templates, but should you require it, you can also pass new variables to it by using the second optional parameter for $this->inc. + + + +:file:`templates/sub.inc.php` + +.. code-block:: php + +
I am included but i can still access the parents variables!
+ + +To access the Template files in your controller, use the TemplateResponse class: .. code-block:: php @@ -395,6 +432,7 @@ Templates reside in the **template/** folder. To use them in your controller, us } ?> +Should you require more template functions, simply modify the TemplateResponse in :file:`lib/response.php` **For more info, see** :doc:`templates`