TemplateStubs by mindplay.dk

ProcessWire module that generates stub classes for IDE support. This is a useful tool for Template development for those using IDEs with static analysis, such as PhpStorm, NetBeans, etc.

TemplateStubs

ProcessWire module that generates stub classes for IDE support.

This is a useful tool for Template development for those using IDEs with static analysis, such as PhpStorm, NetBeans, etc.

The module generates a file named "stubs.php" in the TemplateStubs folder, so make sure this folder is write-enabled. The entire documentation file is rebuilt after saving a Template or Field, which adds overhead - do not deploy this module in production, this is a development tool only.

To make use of the generated stub classes, add an annotation to the top of your template-file - for example, in the top of your "basic-page" template, you would add the following:

<?php

/**
 * @var tpl\basic_page $page
 */

This should enable an IDE with static analysis to auto-complete properties of the $page object, defined by the Fields used in the Template.

Because everything is a Page in ProcessWire, the built-in templates for things like "admin", "role" and "user" will also be documented, which means you can have IDE support for internal templates in modules, for any custom user-fields, etc.

In addition, a special class (e.g. tpl\any) will be generated, documenting all available Fields - this may be useful in situations where you have code intended to work with all (or certain) Fields, e.g. any type of Page.

Example


The output from this module looks like this:

<?php

/**
 * Generated by TemplateStubs module 2013-04-14 11:20:10
 * This file may be overwritten at any time.
 */

namespace tpl;

use Pageimages, Pageimage, PageArray, Page, Password;

/**
 * "admin" template
 *
 * @property string $title Title
 * @property string $process The process that is executed on this page. Since this
 *                           is mostly used by ProcessWire internally, it is
 *                           recommended that you don't change the value of this
 *                           unless adding your own pages in the admin.
 */
class admin extends Page
{}

/**
 * "basic-page" template
 *
 * @property string $title Title
 * @property string $headline Use this instead of the Title if a longer headline is
 *                            needed than what you want to appear in navigation.
 * @property string $summary Summary
 * @property string $body Body Content Yea
 * @property string $sidebar Sidebar
 * @property Pageimages|Pageimage[] $images Images
 */
class basic_page extends Page
{}

/**
 * "permission" template
 *
 * @property string $title Title
 */
class permission extends Page
{}

/**
 * "role" template
 *
 * @property PageArray|Page[] $permissions Permissions
 */
class role extends Page
{}

/**
 * "user" template
 *
 * @property Password $pass Set Password
 * @property string $email E-Mail Address
 * @property PageArray|Page[] $roles User will inherit the permissions assigned to
 *                                   each role. You may assign multiple roles to a
 *                                   user. When accessing a page, the user will
 *                                   only inherit permissions from the roles that
 *                                   are also assigned to the page's template.
 */
class user extends Page
{}

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Twitter updates

  • There’s a new modules directory on the ProcessWire site now up and running. In this post we’ll cover a few details about what’s changed and what’s new—More
    20 November 2020
  • ProcessWire 3.0.168 core updates — More
    26 October 2020
  • This week a 2nd new module for processing Stripe payments has been added to FormBuilder. Unlike our other Stripe Inputfield, this new one supports 3D Secure (SCA) payments. We’ll take a closer look at it in this post, plus a live demo— More
    16 October 2020

Latest news

  • ProcessWire Weekly #342
    In the 342nd issue of ProcessWire Weekly we're going to check out brand new admin theme called Admin Theme Canvas, a new module called MatomoWire, latest ProcessWire core updates, and more. Read on!
    Weekly.pw / 28 November 2020
  • New ProcessWire modules directory
    There’s a new modules directory on the ProcessWire site now up and running. In this post we’ll cover a few details about what’s changed and what’s new.
    Blog / 20 November 2020
  • 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