mirror of
https://github.com/friendica/friendica
synced 2024-09-24 05:11:22 +02:00
obsolete template syntax and update get_markup_template() documentation
parent
5204050b9c
commit
fc8f0c75fa
|
@ -1,9 +1,11 @@
|
|||
friendica has a template system. We are trying to separate html from php (wich is also a good think if we want a mobile teme).
|
||||
This template system allows variables substitution, a minimal logic and possibility to include a template in another template.
|
||||
In 'view' folder there are some template for form fields, ready to be included, so that every form looks the same throughout the site.
|
||||
In 'view/templates' folder there are some template for form fields, ready to be included, so that every form looks the same throughout the site.
|
||||
|
||||
#A quick guide#
|
||||
##1 - template syntax.###
|
||||
##1 - template syntax. OBSOLETE###
|
||||
|
||||
**Friendica default template engine is now Smarty3. Refer to smarty3 documentation**
|
||||
|
||||
###Variables###
|
||||
|
||||
|
@ -81,12 +83,17 @@ example:
|
|||
|
||||
In friendica, templates are used with two functions:
|
||||
|
||||
get_markup_template($templatename);
|
||||
get_markup_template($templatename, [$root]);
|
||||
replace_macro($tpl, $array);
|
||||
|
||||
The first function search _$templatename_ in _view/theme/$currenttheme_ and _view/_ and return its content.
|
||||
_get_markup_template()_ search _$templatename_ in _$root/theme/templates/$currenttheme_ and _$root/templates_ and return its content. If _$root_ is not defined, defaults to _view/_
|
||||
|
||||
The second replace _$array_ in template content.
|
||||
Addons can load custom templates saving template files in _templates/_ subfolder, and calling _get_markup_template()_ with plugin relative path as _$root_:
|
||||
|
||||
$tpl = get_markup_template("mytemplate.tpl", "addon/myplugin/");
|
||||
|
||||
|
||||
_replace_macro()_ replace _$array_ in template content.
|
||||
|
||||
file: test.tpl
|
||||
Hello $name! {{ if $isback }} Welcome back! {{ endif }}
|
||||
|
@ -105,7 +112,7 @@ result:
|
|||
|
||||
##Form fields templates##
|
||||
|
||||
In view/ folder there are many template for form fields.
|
||||
In view/template folder there are many template for form fields.
|
||||
|
||||
- **field_input.tpl**: prints a text input
|
||||
- **field_password.tpl**: prints a password input
|
||||
|
@ -143,7 +150,4 @@ The $field var is an array:
|
|||
- field_select_raw: prebuild html string of < option > tags
|
||||
- field_yesno: custom labels for OFF and ON in array ("label off","label on"
|
||||
|
||||
A trick in addons to load a template from addon folder:
|
||||
|
||||
in addon/myaddon/myaddon.php
|
||||
$tpl = file_get_content(dirname(__file__)."/mytemplate.tpl";
|
||||
|
|
Loading…
Reference in a new issue