[Pkg-owncloud-commits] [owncloud-doc] 58/270: add template docs

David Prévot taffit at moszumanska.debian.org
Thu Jul 31 03:53:01 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud-doc.

commit dc13b3502bd387697ab5c5d6516a58d561d7b1c8
Author: Bernhard Posselt <dev at bernhard-posselt.com>
Date:   Sun May 11 16:26:35 2014 +0200

    add template docs
---
 developer_manual/app/templates.rst | 48 ++++++++++++++++++++++++++++----------
 1 file changed, 36 insertions(+), 12 deletions(-)

diff --git a/developer_manual/app/templates.rst b/developer_manual/app/templates.rst
index a46ca2f..3d988e2 100644
--- a/developer_manual/app/templates.rst
+++ b/developer_manual/app/templates.rst
@@ -1,11 +1,21 @@
+=========
 Templates
 =========
 
 .. sectionauthor:: Bernhard Posselt <dev at bernhard-posselt.com>
 
-ownCloud provides its own templating system.
+ownCloud provides its own templating system which is basically plain PHP with some additional functions and preset variables. All the parameters which have been passed from the :doc:`controller <controllers>` are available in an array called **$_[]**, e.g.::
+    
+    array('key' => 'something')
+
+can be accessed through::
+
+    $_['key']
+
+
+.. note:: To prevent XSS the following PHP **functions for printing are forbidden: echo, print() and <?=**. Instead use the **p()** function for printing your values. Should you require unescaped printing, **double check for XSS** and use: :php:func:`print_unescaped`.
 
-In every template file you can easily access the template functions listed in :doc:`../app/api/templates`. 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']).
+Printing values is done by using the **p()** function, printing HTML is done by using **print_unescaped()**
 
 :file:`templates/main.php`
 
@@ -16,21 +26,18 @@ In every template file you can easily access the template functions listed in :d
   <?php
   }
 
-  print_unescaped($this->inc('sub.inc'));
-
-  ?>
+  
+Including templates
+===================
 
-.. warning::
-  .. versionchanged:: 5.0
+Templates can also include other templates by using the **$this->inc('templateName')** method. 
 
-  To prevent XSS the following PHP **functions for printing are forbidden: echo, print() and <?=**. Instead use the **p()** function for printing your values. Should you require unescaped printing, **double check for XSS** and use: :php:func:`print_unescaped`.
+.. code-block:: php
 
-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.
+  <?php print_unescaped($this->inc('sub.inc')); ?>
 
 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 as array for **$this->inc**.
 
-
-
 :file:`templates/sub.inc.php`
 
 .. code-block:: php
@@ -40,5 +47,22 @@ The parent variables will also be available in the included templates, but shoul
   
   <?php print_unescaped($this->inc('other_template', array('variable' => 'value'))); ?>
 
+Including CSS and JavaScript
+============================
+To include CSS or JavaScript use the **addStyle** and **addScript** functions:
+
+.. code-block:: php
+
+  <?php
+  \OCP\Util::addScript('myapp', 'script');  // add js/script.js
+  \OCP\Util::addStyle('myapp', 'style');  // add css/style.css
+
+
+Including images
+================
+To generate links to images use the **imagePath** function:
+
+.. code-block:: php
+ 
+  <img src="<?php\OCP\Util::imagePath('myapp', 'app.png'); // img/app.pnp?> />
 
-**For more info, see** :doc:`../app/api/templates`
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-doc.git



More information about the Pkg-owncloud-commits mailing list