This example demonstrates the usage of Backdrop theming.
This module attempts to show how module developers can add theme functions to their projects so that themes can modify output.
Module developers should strive to avoid hard-wiring any HTML into the output of their code; this should all be done in theme functions.
Starting with the first example, theming_example_page(): The output is put into a $content array which is then fed to a theming function, theme_theming_example_page(), which loops over the content, wrapping it in HTML markup.
In order to get theme_theming_example_page() recognized, it needs to be registered with hook_theme(). theming_example_theme() does this for this module.
theming_example_list_page() and theming_example_order_form() work in the same way.
In theme_theming_example_list_page(), the content is themed as an ordered list and given a class attribute, theming_example_mylist, which is defined in theming_example.css.
In theme_theming_example_order_form(), the title is loaded into a temporary variable, $title, deleted from the $form array, and output wrapped in HTML markup. The rest of the form is wrapped in a div using '#prefix' and '#suffix'.
The theming functions can be copied to a theme's template.php, renaming them appropriately. For example, if your theme is called 'mytheme', you would copy theme_theming_example_page() to mytheme_theming_example_page() in the template.php file, and it will be used instead of theme_theming_example_page().
The fourth example shows the use of a template file, theming_example_text_form.tpl.php. This file can be copied to a theme's folder, and it will be instead used.
This example also shows what can be done using Backdrop's template_preprocess_HOOK(). In this case, it modifies the output so that a themer can output the whole form, or gain control over some of its parts in the template file.
Parent topics
File
- modules/
examples/ theming_example/ theming_example.module, line 7 - Hook implementations for the Theming Example module.
Functions
Name | Location | Description |
---|---|---|
template_preprocess_theming_example_text_form |
modules/ |
Implements template_preprocess(). |
theme_theming_example_content_array |
modules/ |
Theme a simple content array. |
theme_theming_example_list |
modules/ |
Theming a simple list. |
theme_theming_example_select_form |
modules/ |
Theming a simple form. |
theming_example_list_page |
modules/ |
The list page callback. |
theming_example_menu |
modules/ |
Implements hook_menu(). |
theming_example_page |
modules/ |
Initial landing page explaining the use of the module. |
theming_example_select_form |
modules/ |
A simple form that displays a select box and submit button. |
theming_example_select_form_submit |
modules/ |
Submit handler for the select form. |
theming_example_text_form |
modules/ |
A simple form that displays a textfield and submit button. |
theming_example_text_form_submit |
modules/ |
Submit handler for the text form. |
theming_example_theme |
modules/ |
Implements hook_theme(). |
Classes
Name | Location | Description |
---|---|---|
ThemingExampleTestCase |
modules/ |
Functional tests for the theming example module. |