On this page
Pattern Syntax: Variables
Last updated on
30 April 2025
Many modules store their settings to Drupal's variables table and in all such cases "variables" action should be used instead of "form".
This Example sets three different variables for three different modules:
- set Anonymous vote rollover to 1 hour (votingapi module)
- set fivestar widget display to craft (fivestar module)
- set minimum cache lifetime to 6 hours (system module)
Example (XML):
<actions>
<variables>
<variable name="votingapi_anonymous_window">3600</variable>
<variable name="fivestar_widget">
sites/all/modules/fivestar/widgets/craft/craft.css
</variable>
<variable name="cache_lifetime">21600</variable>
</variables>
</actions>
Another example
The Patterns module also provides this example for complex/multi-dimensional variables:
<!-- Recommended way of defining complex variables -->
<variable name="theme_settings">
<toggle_node_info_page>0</toggle_node_info_page>
<toggle_node_info_example>0</toggle_node_info_example>
<toggle_node_info_blog>1</toggle_node_info_blog>
<toggle_favicon>0</toggle_favicon>
</variable>
The above example is corresponding to the theme_settings variable serialized in the variable table as:
a:3:{s:21:"toggle_node_info_page";b:0;
s:24:"toggle_node_info_example";b:0;
s:21:"toggle_node_info_blog";b:1;
s:14:"toggle_favicon";b:0;}
note: The serialized value has some line breaks inserted for easier reading.
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion