From 8b20af6ef536e34c3bc9c412cbffa4cf9c0cea53 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 16 Jan 2015 19:31:23 +0100 Subject: [PATCH 1/6] template for input fields now supports required, autofocus and types email, url --- view/templates/field_input.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/templates/field_input.tpl b/view/templates/field_input.tpl index 41a636fca4..457ae946e3 100644 --- a/view/templates/field_input.tpl +++ b/view/templates/field_input.tpl @@ -1,6 +1,6 @@
- + {{$field.3}}
From 3483cd35f8b6cb62f3571a3024929a4acd5dac37 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 16 Jan 2015 19:32:31 +0100 Subject: [PATCH 2/6] use HTML5 attributes in the installer wizard --- mod/install.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mod/install.php b/mod/install.php index 484846ccd6..c6fe708362 100755 --- a/mod/install.php +++ b/mod/install.php @@ -231,11 +231,11 @@ function install_content(&$a) { '$status' => $wizard_status, - '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, ''), - '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, ''), - '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, ''), - '$dbdata' => array('dbdata', t('Database Name'), $dbdata, ''), - '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.')), + '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'), + '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'), + '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, '', 'required'), + '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'), + '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'), @@ -274,7 +274,7 @@ function install_content(&$a) { '$dbdata' => $dbdata, '$phpath' => $phpath, - '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.')), + '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'), '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''), From d58bac113840b9bc5e2186d2164c5530ef57a8a0 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 16 Jan 2015 19:36:09 +0100 Subject: [PATCH 3/6] template for password now support required and autofocus --- view/templates/field_input.tpl | 2 +- view/templates/field_password.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/view/templates/field_input.tpl b/view/templates/field_input.tpl index 457ae946e3..ae8fe844a3 100644 --- a/view/templates/field_input.tpl +++ b/view/templates/field_input.tpl @@ -1,6 +1,6 @@
- + {{$field.3}}
diff --git a/view/templates/field_password.tpl b/view/templates/field_password.tpl index 5dd2c5d3f8..2e9e91529a 100644 --- a/view/templates/field_password.tpl +++ b/view/templates/field_password.tpl @@ -1,6 +1,6 @@
- + {{$field.3}}
From b1b1fe495be6b8a4c2dfe5f51ae148884262a6e8 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 18 Jan 2015 16:15:37 +0100 Subject: [PATCH 4/6] some documentation for the templating engine and basic templates for forms --- doc/Home.md | 1 + doc/snarty3-templates.md | 173 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 doc/snarty3-templates.md diff --git a/doc/Home.md b/doc/Home.md index 031bec8058..592ee977b2 100644 --- a/doc/Home.md +++ b/doc/Home.md @@ -40,6 +40,7 @@ Friendica Documentation and Resources * [Help on Vagrant](help/Vagrant) * [How to translate Friendica](help/translations) * [Bugs and Issues](help/Bugs-and-Issues) +* [Smarty 3 Templates](help/smarty3-templates) **External Resources** diff --git a/doc/snarty3-templates.md b/doc/snarty3-templates.md new file mode 100644 index 0000000000..d23806a00b --- /dev/null +++ b/doc/snarty3-templates.md @@ -0,0 +1,173 @@ +Friendica Templating Documentation +================================== + +* [Home](help) + +Friendica uses [Smarty 3](http://www.smarty.net/) as PHP templating engine. The main templates are found in + + /view/templates + +theme authors may overwrite the default templates by putting a files with the same name into the + + /view/themes/$themename/templates + +directory. + +Templates that are only used by addons shall be placed in the + + /addon/$addonname/templates + +directory. + +To render a template use the function *get_markup_template* to load the template and *replace_macros* to replace the markros/variables in the just loaded template file. + + $tpl = get_markup_template('install_settings.tpl'); + $o .= replace_macros($tpl, array( ... )); + +the array consists of an association of an identifier and the value for that identifier, i.e. + + '$title' => $install_title, + +where the value may as well be an array by its own. + +Form Templates +-------------- + +To guarantee a consistent look and feel for input forms, i.e. in the settings sections, there are templates for the basic form fields. They are initialized with an array of data, depending on the tyle of the field. + +All of these take an array for holding the values, i.e. for an one line text input field, which is required and should be used to type email addesses use something along + + '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.'), 'required', '', 'email'), + +To evaluate the input value, you can then use the $_POST array, more precisely the $_POST['adminemail'] variable. + +Listed below are the template file names, the general purpose of the template and their field parameters. + +### field_checkbox.tpl + +A checkbox. If the checkbox is checked its value is **1**. Field parameter: + +0. Name of the checkbox, +1. Label for the checkbox, +2. State checked? if true then the checkbox will be marked as checked, +3. Help text for the checkbox. + +### field_combobox.tpl + +A combobox, combining a pull down selection and a textual input field. Field parameter: + +0. Name of the combobox, +1. Label for the combobox, +2. Current value of the variable, +3. Help text for the combobox, +4. Array holding the possible values for the textual input, +5. Array holding the possible values for the pull down selection. + +### field_custom.tpl + +A customizeable template to include a custom element in the form with the usual surroundings, Field parameter: + +0. Name of the field, +1. Label for the field, +2. the field, +3. Help text for the field. + +### field_input.tpl + +A single line input field for textual input. Field parameter: + +0. Name of the field, +1. Label for the input box, +2. Current value of the variable, +3. Help text for the input box, +4. if set to "required" modern browser will check that this input box is filled when submitting the form, +5. if set to "autofocus" modern browser will put the cursur into this box once the page is loaded, +6. if set to "email" or "url" modern browser will check that the filled in value corresponds to an email address or URL. + +### field_intcheckbox.tpl + +A checkbox (see above) but you can define the value of it. Field parameter: + +0. Name of the checkbox, +1. Label for the checkbox, +2. State checked? if true then the checkbox will be marked as checked, +3. Value of the checkbox, +4. Help text for the checkbox. + +### field_openid.tpl + +An input box (see above) but prepared for special CSS styling for openID input. Field parameter: + +0. Name of the field, +1. Label for the input box, +2. Current value of the variable, +3. Help text for the input field. + +### field_password.tpl + +A single line input field (see above) for texttual input. The characters typed in will not be shown by the browser. Field parameter: + +0. Name of the field, +1. Label for the field, +2. Value for the field, e.g. the old password, +3. Help text for the input field, +4. if set to "required" modern browser will check that this field is filled out, +5. if set to "autofocus" modern browser will put the cursor automatically into this input field. + +### field_radio.tpl + +A radio button. Field parameter: + +0. Name of the radio button, +1. Label for the radio button, +2. Current value of the variable, +3. Help text for the button, +4. if set, the radio button will be checked. + +### field_richtext.tpl + +A multi-line input field for *rich* textual content. Field parameter: + +0. Name of the input field, +1. Label for the input box, +2. Current text for the box, +3. Help text for the input box. + +### field_select.tpl + +A drop down selection box. Field parameter: + +0. Name of the field, +1. Label of the selection box, +2. Current selected value, +3. Help text for the selection box, +4. Array holding the possible values of the selection drop down. + +### field_select_raw.tpl + +A drop down selection box (see above) but you have to prepare the values yourself. Field parameter: + +0. Name of the field, +1. Label of the selection box, +2. Current selected value, +3. Help text for the selection box, +4. Possible values of the selection drop down. + +### field_textarea.tpl + +A multi-line input field for (plain) textual content. Field parameter: + +0. Name of the input field, +1. Label for the input box, +2. Current text for the box, +3. Help text for the input box. + +### field_yesno.tpl + +A button that has two states *yes* or *no*. Field parameter: + +0. Name of the input field, +1. Label for the button, +2. Current value, +3. Help text for the button +4. if set to an array of two values, these two will be used, otherwise "off" and "on". From c5200f9327852117a951524c5657b65180b86ad8 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 19 Jan 2015 08:15:20 +0100 Subject: [PATCH 5/6] profile edit homepage field type URL --- view/templates/profile_edit.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/templates/profile_edit.tpl b/view/templates/profile_edit.tpl index 8a00bd6e06..b68ec5081d 100644 --- a/view/templates/profile_edit.tpl +++ b/view/templates/profile_edit.tpl @@ -131,7 +131,7 @@
- +
From 3a3ea18384fa1c5293ddd7dfc1a53c0ada120790 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Tue, 20 Jan 2015 21:23:27 +0100 Subject: [PATCH 6/6] typos --- doc/snarty3-templates.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/snarty3-templates.md b/doc/snarty3-templates.md index d23806a00b..751ef20b31 100644 --- a/doc/snarty3-templates.md +++ b/doc/snarty3-templates.md @@ -19,7 +19,7 @@ Templates that are only used by addons shall be placed in the directory. -To render a template use the function *get_markup_template* to load the template and *replace_macros* to replace the markros/variables in the just loaded template file. +To render a template use the function *get_markup_template* to load the template and *replace_macros* to replace the macros/variables in the just loaded template file. $tpl = get_markup_template('install_settings.tpl'); $o .= replace_macros($tpl, array( ... )); @@ -105,7 +105,7 @@ An input box (see above) but prepared for special CSS styling for openID input. ### field_password.tpl -A single line input field (see above) for texttual input. The characters typed in will not be shown by the browser. Field parameter: +A single line input field (see above) for textual input. The characters typed in will not be shown by the browser. Field parameter: 0. Name of the field, 1. Label for the field,