phpDocumentor

Using Twig

phpDocumentor provides the Twig 2.x engine as a rendering engine for templates.

Configuration

The Twig engine can be configured in your template's template.xml through the <parameters> tag.

<template>
    <parameters>
        <parameter key="config-key">config-value</parameter>
    </parameters>
</template>

Caching

phpDocumentor enables Twig's compilation cache by default. When developing Twig templates, you need to turn this off in your template.xml by enabling debug mode:

<parameter key="twig-debug">true</parameter>

This will also make the Twig debug extension available, which provides the dump() function.

Reference

Global Variables                 

  • project
  • documentationSet
  • node
  • destinationPath
  • env
  • usesNamespaces
  • usesPackages

Filters        

Functions          

Global Variables

Parameters are also available as twig variables, this allows you to add static values from your configuration files in the rendered output. {{ parameter.param-key }} will give you the value of the parameter param-key.

project

type: ProjectDescriptor

This variable contains the top-level project data generated by phpDocumentor.

node

type: Subclass of DescriptorAbstract for API Documentation, or for reference documentation.

This variable contains the data from the transformation query. This will be one of the Descriptor classes matching the object you query.

Functions

path

{{ path(relative_path) }}
relative_path
type: string

Returns the URL for the given path, relative to the current path.

Filters

markdown

{{ text|markdown }}
text
type: string

Renders Markdown text into HTML, using the Parsedown engine.

trans

{{ message|trans(context = []) }}
message
type: string
context (optional)
type: array default: []

Renders the translation of the content. Variables in context are expanded into the translated text using vsprintf.

route

{{ node|route(presentation = 'normal') }}
node
type: phpDocumentor\Descriptor\DescriptorAbstract
presentation (optional)
type: string default: normal

Renders a link to the generated page for the node. presentation can be set to 'url' to render only the URL.

sort_asc

{{ list|sort_asc }}
list
type: array

Sorts the given list in ascending order by name, case-insensitively. Uses the name of each node in the collection to sort. Typically used for sorting a phpDocumentor\Descriptor\Collection of descriptors.

sort_desc

{{ list|sort_desc }}
list
type: array

Sorts the given list in descending order by name, case-insensitively. Uses the name of each node in the collection to sort. Typically used for sorting a phpDocumentor\Descriptor\Collection of descriptors.

Search results