Introduction to ProcessWire API variables

ProcessWire provides various API variables to every template file. These variables provide full access to all site content. This page provides an introduction on how to use them.

API variables can be accessed in a few different ways. The most common way is as a variable. Here are a few different ways you might access the same $page API variable (as an example):

  • $page the most common access as a variable.

  • page() accessing as a function can be very convenient, when available.

  • wire('page') This works anywhere, and with any version of ProcessWire.

  • $this->page This is how you might access it from within a Wire-derived class.

  • $this->wire('page') A slightly more efficient way you can access from within a Wire-derived class.

  • $pages->wire('page') API variables can also access all other API variables, by way of their wire() method. In this example, we are accessing the $page API variable from the $pages API variable. So if you have any one API variable, then you actually have them all.

Accessing API variables as a function rather than a variable can be more convenient when the variable version may be out of scope, or if your IDE highlights API variables as undefined. So whenever we refer to an API variable, make note that access it however you'd like.

This is just an introduction to some of ProcessWire's API variables. Once you are familiar with these, you'll want to use ProcessWire's full API reference instead.

Some of ProcessWire’s most common API variables

  • $page

    The $page variable is provided to every template, and it contains all the fields specific to the page being viewed. This includes both built-in fields, which are common to all pages, as well as the custom fields.
  • $pages

    While the $page variable holds the current page, the $pages variable is where you can get at all the other pages in your site. It includes functions for getting, finding, saving and deleting pages.
  • $input

    The $input variable is your connection to GET, POST and COOKIE variables, URL segments, page (pagination) numbers, and more.
  • $sanitizer

    The $sanitizer functions are provided to fill the most common data sanitization needs with sites developed in ProcessWire. Always sanitize any data you get from user input.
  • $session

    This API variable provides access to read/write of session variables, login and logout of users, redirects, and more.
  • $fields

    $fields is an API variable that contains all the custom page fields in your site. It provides the API functions available in the admin control panel under Setup > Fields. Use it to retrieve, save or delete custom page fields.
  • $user

    The $user API variable is your connection to the current user viewing the page.
  • $log

    The $log API variable enables you to create, manage and filter log entries. Log files are stored in /site/assets/logs/.
  • $templates

    The $templates API variable provides access to all of your site’s templates. Use the $templates API variable to retrieve, modify, create or delete templates and control what fields are attached to them.
  • $config

    The $config API variable contains all the settings specific to your site configuration. This includes URLs and paths, database configuration, session configuration, and more.

Twitter updates

  • ProcessWire 3.0.133 adds a useful new Page::meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type— More
    14 June 2019
  • New post: This week we’ll take a look at 3 different WEBP image strategies that you can use in ProcessWire 3.0.132+. Then we’ll dive into a major update for the Google Client API module, and finish up by outlining some useful new updates in FormBuilder— More
    31 May 2019
  • New post: This week we've added WEBP support in ProcessWire thanks to a GitHub pull request from Horst Nogajski. This enables you to have highly optimized image output in PW and I think you’ll really like the difference it makes— More
    24 May 2019

Latest news

  • ProcessWire Weekly #267
    In the 267th issue of ProcessWire Weekly we're going to cover the latest changes in the development branch of ProcessWire, introduce a new module called MarkupMenu, and highlight a brand new site of the week. Read on!
    Weekly.pw / 22 June 2019
  • ProcessWire 3.0.133 core updates
    ProcessWire 3.0.133 adds a useful new $page->meta() method for a new type of page-specific persistent data storage, adds the ability for users to create their own bookmarks in Lister, and has a handy and time saving update for the asmSelect input type. Read on for all the details, examples and screenshots.
    Blog / 14 June 2019
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK