Download the PHP package phpdocumentor/plugin-twig without Composer

On this page you can find all versions of the php package phpdocumentor/plugin-twig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package plugin-twig

phpDocumentor Twig Plugin

Installation

This plugin is installed by default with phpDocumentor.

Features

This plugin features the following:

Generating output using Twig

The Twig writer can be used in any transformation in a template (see phpDocumentor's main documentation on Creating templates).

The following line can be added as child to the transformations element:

<transformation
    writer="\phpDocumentor\Plugin\Twig\Transformer\Writer\Twig"
    source="templates/my_twig_template/index.twig"
    artifact="index.html"/>

This tells phpDocumentor to use the Twig writer to use the index.twig template in the /data/templates/my_twig_template folder to generate the index.html file in your destination folder.

Full basic example template:

<?xml version="1.0" encoding="utf-8"?>
<template>
  <author>Mike van Riel</author>
  <email>[email protected]</email>
  <version>1.0.0</version>
  <copyright>Mike van Riel 2012</copyright>
  <description></description>
  <transformations>
      <transformation
        query="copy"
        writer="FileIo"
        source="templates/my_twig_template/stylesheet.css"
        artifact="stylesheet.css"/>
    <transformation
        writer="\phpDocumentor\Plugin\Twig\Transformer\Writer\Twig"
        source="templates/my_twig_template/index.twig"
        artifact="index.html"/>
  </transformations>
</template>

Looping through a resultset

Using transformation it is possible to loop through a set of elements and apply a template on all of them.

Easiest is to demonstrate this using an example:

Suppose that you would want to generate a detailed view of a class using the same template file

You do not know up front which classes there will be so you would need a dynamic transformation. This is possible by adding the 'query' attribute to your transformation and specifying a xpath lookup.

Example transformation for each class entry:

<transformation
    query="/project/file/class"
    writer="\phpDocumentor\Plugin\Twig\Transformer\Writer\Twig"
    source="templates/my_twig_template/class.twig"
    artifact="class.html"/>

The above example would loop through all class elements of the project and pass that to your twig template as root element instead of project.

There is a big problem with the transformation above: the destination file class.html would be overwritten with each subsequent class found and you end up with one file with the last class found.

To fix this you can use an xpath query in your artifact attribute as well to create a dynamic destination filename.

Example transformation for each class entry with a dynamic file name:

<transformation
    query="/project/file/class"
    writer="\phpDocumentor\Plugin\Twig\Transformer\Writer\Twig"
    source="templates/my_twig_template/class.twig"
    artifact="{@full_name}.html"/>

In the above example you can see that a xpath query is provided in braces. This query is executed with the node that was found using the query attribute. Thus in this example the full_name property was taken from the class that is currently being processed.

Writing your own templates

Every template receives a global Twig variable called ast_node. This global Twig variable represents the either the document-root of the Abstract Syntax Tree (which is project) or a childnode if a Query has been used.

Since the Abstract Syntax Tree (and its nodes) are presented as SimpleXMLElement objects you can query them as normal objects from Twig.

Extensions

Using third-party extensions

phpDocumentor allows you to add your own extensions so that they can be used.

Every extension needs to be available for autoloading (so it is common to create a Plugin in this case and include them using the Composer 'require' section).

Once available you can define a parameter 'twig-extension' in your template header of with each individual transformation.

Extensions defined with a transformation override the ones defined in your template.

Example globally defined extension:

<?xml version="1.0" encoding="utf-8"?>
<template>
    <parameters>
        <twig-extension>
            \phpDocumentor\Plugin\MyPlugin\Twig\Extension
        </twig-extension>
    </parameters>
    <transformations>
        <transformation
            writer="\phpDocumentor\Plugin\Twig\Transformer\Writer\Twig"
            source="templates/twig/index.twig"
            artifact="index.html"/>
    </transformations>
</template>

Example extension defined with an individual transformation:

<?xml version="1.0" encoding="utf-8"?>
<template>
    <transformations>
        <transformation
            writer="\phpDocumentor\Plugin\Twig\Transformer\Writer\Twig"
            source="templates/twig/index.twig"
            artifact="index.html"
        >
            <parameters>
                <twig-extension>
                    \phpDocumentor\Plugin\MyPlugin\Twig\Extension
                </twig-extension>
            </parameters>
        </transformation>
    </transformations>
</template>

Writing your own extensions


All versions of plugin-twig with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.3
twig/twig Version >=1.8,<2.0-dev
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phpdocumentor/plugin-twig contains the following files

Loading the files please wait ....