Example: Theming
Same name in other branches
- 3.x modules/theming_example/theming_example.module \theming_example
- 7.x-1.x theming_example/theming_example.module \theming_example
Example of Drupal theming.
The Theming Example 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-coding 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 an array $content, which is then fed to theme_theming_example_content_array(), which loops over the content, wrapping it in HTML markup in the process.
In order to get theme_theming_example_content_array() recognized, it needs to be registered in a hook_theme() implementation, theming_example_theme() in this case.
theming_example_list_page() and theming_example_order_form() work in the same way.
In theming-example-list.html.twig, the content is themed as an ordered list and given the theming-example-list class attribute, which is defined in theming_example.css
The fourth example shows the use of theming_example_text_form.tpl.php. This file can be copied to a theme's folder, and it will be used instead.
This example also shows what can be done using template_preprocess_HOOK(). In this case it modifies the output to allow a theme developer to output the whole form or gain control over some of its parts in the template file.
Parent topics
File
-
modules/
theming_example/ theming_example.module, line 17
Functions
Title Sort descending | File name | Summary |
---|---|---|
theming_example_form_alter | modules/ |
Implements hook_form_alter(). |
theming_example_preprocess_form_element_label | modules/ |
Implements hook_preprocess_HOOK(). |
theming_example_theme | modules/ |
Implements hook_theme(). |