wireIncludeFile() function

Include a PHP file passing it all API variables and optionally your own specified variables

This is the procedural version of the $files->include() method.

This is the same as PHP’s include() function except for the following:

  • It receives all API variables and optionally your custom variables
  • If your filename is not absolute, it doesn’t look in PHP’s include path, only in the current dir.
  • It only allows including files that are part of the PW installation: templates, core modules or site modules
  • It will assume a “.php” extension if filename has no extension.

Note this function produces direct output. To retrieve output as a return value, use the wireRenderFile() or $files->render() function instead.

Usage

// basic usage
$bool = wireIncludeFile(string $filename);

// usage with all arguments
$bool = wireIncludeFile(string $filename, array $vars = array, array $options = include);

Arguments

NameType(s)Description
filenamestring

Filename to include

vars (optional)array

Optional variables you want to hand to the include (associative array)

options (optional)array

Array of options to modify behavior:

  • func (string): Function to use: include, include_once, require or require_once (default=include)
  • autoExtension (string): Extension to assume when no ext in filename, make blank for no auto assumption (default=php)
  • allowedPaths (array): Array of start paths include files are allowed from. Note current dir is always allowed.

Return value

bool

Always returns true

Exceptions

Method can throw exceptions on error:

  • WireException - if file doesn’t exist or is not allowed

See Also


Functions methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #520
    In the 520th issue of ProcessWire Weekly we'll check out some of the latest additions to the ProcessWire module's directory, share some highlights from the latest weekly update from Ryan, and more. Read on!
    Weekly.pw / 27 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits