Get or set an output region (primarily for front-end output usage)

This function is an convenience for storing markup that ultimately gets output in a _main.php file (or whatever file $config->appendTemplateFile is set to). It is an alternative to passing variables between included files and provides an interface for setting, appending, prepending and ultimately getting markup (or other strings) for output. It’s designed for use the the “Delayed Output” strategy, though does not necessarily require it.

This function can also be accessed as wireRegion(), and that function is always available regardless of whether the Functions API is enabled or not.

Note: unlike other functions in the Functions API, this function is not related to API variables.

Example

// define a region
region('content', '<p>this is some content</p>');

// prepend some text to region
region('+content', '<h2>Good morning</h2>');

// append some text to region
region('content+', '<p><small>Good night</small></p>');

// output a region
echo region('content');

// get all regions in an array
$regions = region('*');

// clear the 'content' region
region('content', '');

// clear all regions
region('*', '');

Usage

// basic usage
$string = region();

// usage with all arguments
$string = region(string $key = '', $value = null);

Arguments

NameType(s)Description
key (optional)string

Name of region to get or set.

  • Specify "*" to retrieve all defined regions in an array.
  • Prepend a "+" to the region name to have it prepend your given value to any existing value.
  • Append a "+" to the region name to have it append your given value to any existing value.
  • Prepend a "++" to region name to make future calls without "+" automatically prepend.
  • Append a "++" to region name to make future calls without "+" to automatically append.
value (optional)null, string

If setting a region, the text that you want to set.

Return value

string null bool array

Returns string of text when getting a region, NULL if region not set, or TRUE if setting region.


Functions methods and properties

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • ProcessWire 3.0.146 on the dev branch contains about 22 commits with a combination of useful upgrades and issue report resolutions, more details in this forum post: More
    22 November 2019
  • ProcessWire 3.0.144 and 3.0.145 add improved field template context override settings and include a new Inputfields API, along with numerous other issue fixes, optimizations and improvements to the core. More
    8 November 2019
  • ProcessWire 3.0.144 core updates: Upgraded overrides section in the field editor, a new Inputfields JS API, and more— More
    1 November 2019

Latest news

  • ProcessWire Weekly #290
    In the 290th issue of ProcessWire Weekly we're going to introduce the latest addition to the ProDevTools module package and a third party image picker field from gebeer, check out a new site of the week, and more. Read on!
    Weekly.pw / 30 November 2019
  • New User Activity module
    Blog / 29 November 2019
  • Subscribe to weekly ProcessWire news

I just love the easy and intuitive ProcessWire API. ProcessWire rocks!” —Jens Martsch, Web developer