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 #549
    In the 549th issue of ProcessWire Weekly we’re going to check out the latest core updates, highlight one older yet still very relevant third party module, and more. Read on!
    Weekly.pw / 17 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer