Rewrote page after yesno field removal

master
Hypolite Petovan 2020-02-05 21:04:43 -05:00
parent 1d28142401
commit 2331327b18
1 changed files with 20 additions and 93 deletions

@ -2,91 +2,20 @@ friendica has a template system. We are trying to separate html from php (wich
This template system allows variables substitution, a minimal logic and possibility to include a template in another template.
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. OBSOLETE###
# A quick guide
**Friendica default template engine is now Smarty3. Refer to smarty3 documentation**
## 1 - Template syntax
###Variables###
Friendica uses the Smarty 3 template engine, please refer to [the official Smarty 3 manual](https://www.smarty.net/docs/en/smarty.for.designers.tpl).
Variables starts with _$_
## 2 - PHP side
Welcome $name
In Friendica, templates are used with two functions:
Friendica\Core\Renderer::getMarkupTemplate($templatename, [$root]);
Friendica\Core\Renderer::replaceMacros($tpl, $array);
Is possible to pass an array to template. Refer to array items with the form _$varname.key_
in php:
$user = Array( 'name'=>'John', 'enabled'=>false)
in template:
Welcome $user.name
###Logic blocks###
Logic block are in the form _{{ name opts }}...{{ endname }}_
####Conditional: IF####
syntax:
{{ if <$var> }}...[{{ else }} ...] {{ endif }}
{{ if <$var>==<$var|str> }}...[{{ else }} ...]{{ endif }}
{{ if <$var>!=<$var|str> }}...[{{ else }} ...]{{ endif }}
examples:
{{ if $user.enabled }} Ok. {{ endif }}
{{ if $user.enabled }}
<span>$user.name</span>
{{ else }}
<span>$user.name</span>
{{ endif }}
####Loop: FOR####
syntax:
{{ for <$var> as $name }}...{{ endfor }}
{{ for <$var> as $key=>$name }}...{{ endfor }}
example:
{{ for $items as $item}}
< h1 >$item.title< /h1 >;
$item.body
{{ endfor }}
####Include: INC####
syntax:
{{ inc [with $var1=$var2] }}{{ endinc }}
example:
file: field_text.tpl
< label for="id_$field.name">$field.label< /label >
< input id="id_$field.name" name="$field.name" value="$field_value" />
file: form.tpl
< form >
{{ inc field_text.tpl with $field=$username }}{{ endinc }}
{{ inc field_text.tpl with $field=$useremail }}{{ endinc }}
< /form >
##2 - PHP side##
In friendica, templates are used with two functions:
get_markup_template($templatename, [$root]);
replace_macro($tpl, $array);
_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/_
_Renderer::getMarkupTemplate()_ search _$templatename_ in _$root/theme/templates/$currenttheme_ and _$root/templates_ and return its content. If _$root_ is not defined, defaults to _view/_
Addons can load custom templates saving template files in _templates/_ subfolder, and calling _get_markup_template()_ with plugin relative path as _$root_:
@ -110,7 +39,7 @@ result:
Hello Anna!
##Form fields templates##
## Form fields templates
In view/template folder there are many template for form fields.
@ -121,33 +50,31 @@ In view/template folder there are many template for form fields.
- **field_radio.tpl**: prints a radio input
- **field_checkbox.tpl**: prints a checkbox input with value=1
- **field_intcheckbox.tpl**: prints a checkbox input with a custom value
- **field_yesno.tpl**: a javascript-enanched checkbox. Show a slider button with "ON/OFF" or custom labels
- **field_select.tpl**: prints a select input. options are passed as key=>value array.
- **field_select_raw.tpl**: a select input, but options are passed as prebuild html string
- **field_select_raw.tpl**: a select input, but options are passed as prebuilt html string
- **field_openid.tpl**: a text input styled with openid icon
- **field_custom.tpl**: field template without input tag. Is passed as prebuild html string
- **field_custom.tpl**: field template without input tag. Is passed as prebuilt html string
Every field_* template expect a var called $field. A field template is included like this:
{{ inc field_input.tpl with $field=$myvar }}{{ endinc }}
{{include file=field_input.tpl field=$myvar}}
The $field var is an array:
$field = array('name', 'Label', value, '[optional help text]', [extra data] )
$field = ['name', 'Label', value, '[optional help text]', <extra data>]
- _'name'_ is the name assigned to html element
- _'Label'_ is the string printed for element label
- _value_ is the value of field
- field_checkbox want a value that can be evaluated to 'true' or 'false' to set the field checked or not (usually 1 or 0).
- field_select use this to find the currently selected option
- field_custon expects this to be the prebuild imput html string
- _'optional text help'_ is a text printed under input to give more detail on what he shoud input. Could be an empty string.
- field_checkbox want a value that can be evaluated to 'true' or 'false' to set the field checked or not (usually 1 or 0).
- field_select use this to find the currently selected option
- field_custom expects this to be the prebuilt input html string
- _'optional text help'_ is a text printed under input to give more detail on what he should input. Could be an empty string.
- _extra data_ is data needed by some templates
- field_select: array(key=>value,..) to use in < option > tags as value=>label
- field_intcheckbox: value of input element
- field_select_raw: prebuild html string of < option > tags
- field_yesno: custom labels for OFF and ON in array ("label off","label on"
- field_select: array(key=>value,..) to use in < option > tags as value=>label
- field_intcheckbox: value of input element
- field_select_raw: prebuilt HTML string of < option > tags