When a user requests a page, Typemill initiates the application, loads plugins, merges settings, starts the template engine, scans the content folder, collects content, and finally renders the page. These steps collectively form the life cycle of Typemill.

Throughout this life cycle, Typemill consistently fires events and often sends data with these events. Developers can listen to these events, hook into the system, and add their own functionality.

Event Overview

Here is a list of events that Typemill fires during its life cycle, ordered accordingly. The last column specifies the data passed to your subscriber method.

Event Name Description Data
onPluginsLoaded Typemill has loaded all plugins. array $plugins
onSettingsLoaded Typemill has loaded and merged all settings. array $settings
onRolesPermissionsLoaded Typemill has loaded the roles and permissions. array $rolesAndPermissions
onResourcesLoaded Typemill has loaded the resources (simple strings), where a role has a permission to. array $resources
onSessionSegmentsLoaded Typemill has loaded all session segments. A session segment is a part of the url like /tm/ that starts a session. array $segments
onTwigLoaded Typemill has loaded the template engine Twig. No data
onUserfieldsLoaded Typemill has loaded the input-field-definitions of a user for updating his profile depending on his role. array $fieldDefinition
onSystemnaviLoaded Typemill has loaded the navigation for the system settings in the author interface. array $systemnavi
onPagetreeLoaded Typemill has scanned the content folder, and has generated the content-navigation. array of objects $navigation
onBreadcrumbLoaded Typemill has created a breadcrumb for the page. array $breadcrumb
onItemLoaded Typemill has created the page item. obbject $item
onMetaLoaded Typemill has loaded the meta-information of a page. array $meta
onRestrictionsLoaded Typemill has loaded the content-restrictions for a page array $restrictionSnippetAndFullContent
onMarkdownLoaded Typemill has loaded the page content. string $pagecontent (markdown)
onContentArrayLoaded Typemill has transformed the page content into an array. array $contentstructure
onShortcodeFound Typemill has found a shortcode in the content. array $shortcode
onHtmlLoaded Typemill has transformed the Markdown content to HTML. string $html
onPageReady Typemill has collected all data for the page, and will send it to the template in the next step. array $pagedata
onPagePublished Typemill has published a content page. object $pageItem
onPageUnpublished Typemill has unpublished a content page. object $pageItem
onPageDeleted Typemill has deleted a page. object $pageItem
onPageSorted Typemill has sorted/moved a page. array $pageItemWithOldAndNewIndex

Life Cycle Variations

Note that the life cycle of Typemill can vary based on specific contexts. For example: The admin area does not fire events for content rendering since the content is not rendered at all in this context.

These events are fired in all cases:

  • onSettingsLoaded
  • onPluginsLoaded
  • onSessionSegmentsLoaded
  • onRolesPermissionsLoaded
  • onResourcesLoaded
  • onTwigLoaded

These events are only fired for system area:

  • onSystemnaviLoaded

These events are only fired for content pages:

  • onShortcodeFound
  • onPagetreeLoaded
  • onBreadcrumbLoaded
  • onItemLoaded
  • onMarkdownLoaded
  • onMetaLoaded
  • onRestrictionsLoaded
  • onContentArrayLoaded
  • onHtmlLoaded
  • onPageReady

Get and Return Event-Data

If Typemill passes data to your subscriber method, then you can get the data, use the data, manipulate the data, and return the data to the app. You can do this with two simple methods: getData() and setData().

Let's take the HTML event as an example:

use Typemill\Plugin;

class MyPlugin extends Plugin
    public static function getSubscribedEvents()
        return array(
            'onHtmlLoaded'      => 'onHtmlLoaded'

    public function onHtmlLoaded($html)
        $data = $html->getData();
        $data .= '<p>This is a paragraph that I added at the end of the page content</p>';      

Other Event-Parameters

TYPEMILL uses the Symfony event dispatcher for the event system. The event dispatcher adds two other variables to each event by default:

  • The second parameter is the name of the event.
  • The third parameter is the event dispatcher itself.

So in each of your event methods in your plugin, you can also read the event name, and you have access to the dispatcher object itself:

public function onHtmlParsed($html, $eventName, $dispatcher)
    // read the $eventName
    // use the $dispatcher

There are not many use cases for accessing the event name or the dispatcher in this way. Theoretically, you could fire your own events with the dispatcher object, but it's much better to access the dispatcher object within Slim's dependency container.

The dependency container is one of the properties and methods provided by TYPEMILL's basic plugin class. Because all plugins extend this basic plugin class, all plugins have access to these useful properties and methods.