3: Initialization, constants, and the NV class

The NV class performs all the theme framework’s initialization/bootstrapping; it loads all the classes, other framework files, theme hooks, and components. It is located in NV/NV.php.

When starting a new project, this is usually the first file you should look at. This article will deal almost exclusively with this file.

Triggering Initialization

By using a singleton pattern for the NV class we can ensure that hooks are never accidentally executed more than once. This pattern also allows us to drop sloppy global theme constants in favor of nice, scope-appropriate class properties. Although the class is initialized automatically, you can access the singleton instance at any time by calling \NV\Theme\NV::i().

Initialization Overview

Step 1: Set Properties

The first thing the class does is load all necessary theme properties. In NOUVEAU, you have two primary property objects:

  1. NV::i()->path
    This object includes a list of system paths for all of NOUVEAUs main includable files and directories.
  2. NV::i()->url
    This object includes a list of URLs for all of NOUVEAUs main URL-accessable files and directories.

For a full list of properties, see NV/NV.php

Step 2: Load Language

If available and configured, language files are loaded by NV::languages().

Step 3: Execute Hooks

Finally, all the hooks needed to set up the theme are executed by NV::hooks(). You should place your own hooks in this method… but before you add new hooks, have a quick look here to see if the hook you want to use is already configured.

If you are just getting started with NOUVEAU, you should be able to learn just about everything you need to know by taking a look at the NV::hooks() method. It’s fully commented and organized for quick and easy reading.

This page was last updated on September 15, 2016 – it is currently considered BEING REVISED.