Skip to content

Latest commit

 

History

History
388 lines (372 loc) · 19.2 KB

05_twigCustomFunctions.md

File metadata and controls

388 lines (372 loc) · 19.2 KB

BumbleDocGen / Technical description of the project / Renderer / Template functions


Template functions

When generating pages, you can use functions that allow you to modify the content. Functions available during page generation are defined in the configuration ( twig_functions parameter )

We use the twig template engine, you can get more information about working with functions here: https://twig.symfony.com/doc/1.x/advanced.html#functions

You can also create your own functions and use them for any purpose, such as loading some additional information into a template, filtering data, or formatting the output of any information. Each function must implement the CustomFunctionInterface interface, implement the __invoke magic method, and be added to the configuration.

How to use a function in a template

{{ functionName(...parameters) }}

Configuration example

You can add your custom functions to the configuration like this:

twig_functions:
  - class: \SelfDocConfig\Twig\CustomFunction\FindEntitiesClassesByCollectionClassName
  - class: \SelfDocConfig\Twig\CustomFunction\PrintClassCollectionAsGroupedTable
  - class: \SelfDocConfig\Twig\CustomFunction\GetConfigParametersDescription

It is important to remember that when a template is inherited, custom functions are not overridden and augmented. This information is detailed on page Configuration files.

Defautl template functions

Several functions are already defined in the base configuration. There are both general functions for all types of entities, and functions that only serve to process entities that belong to a particular PL.

Here is a list of functions available by default:

Function Parameters
name type description
drawDocumentationMenu
Generate documentation menu in HTML format. To generate the menu, the start page is taken, and all links with this page are recursively collected for it, after which the html menu is created.
⚠️ This function initiates the creation of documents for the displayed entities
$startPageKey string | null Relative path to the page from which the menu will be generated (only child pages will be taken into account). By default, the main documentation page (readme.md) is used.
$maxDeep int | null Maximum parsing depth of documented links starting from the current page. By default, this restriction is disabled.
 
drawDocumentedEntityLink
Creates an entity link by object
⚠️ This function initiates the creation of documents for the displayed entities
$entity RootEntityInterface The entity for which we want to get the link
$cursor string Reference to an element inside an entity, for example, the name of a function/constant/property
$useShortName bool Use the full or short entity name in the link
 
fileGetContents
Displaying the content of a file or web resource
$resourceName string Resource name, url or path to the resource. The path can contain shortcodes with parameters from the configuration (%param_name%)
 
generatePageBreadcrumbs
Function to generate breadcrumbs on the page
$currentPageTitle string Title of the current page
$templatePath string Path to the template from which the breadcrumbs will be generated
$skipFirstTemplatePage bool If set to true, the page from which parsing starts will not participate in the formation of breadcrumbs This option is useful when working with the _self value in a template, as it returns the full path to the current template, and the reference to it in breadcrumbs should not be clickable.
 
getDocumentationPageUrl
Creates an entity link by object
$key string The key by which to look up the URL of the page. Can be the title of a page, a path to a template, or a generated document
 
getDocumentedEntityUrl
Get the URL of a documented entity by its name. If the entity is found, next to the file where this method was called, the `EntityDocRendererInterface::getDocFileExtension()` directory will be created, in which the documented entity file will be created
⚠️ This function initiates the creation of documents for the displayed entities
$rootEntityCollection RootEntityCollection Processed entity collection
$entityName string The full name of the entity for which the URL will be retrieved. If the entity is not found, the DEFAULT_URL value will be returned.
$cursor string Cursor on the page of the documented entity (for example, the name of a method or property)
$createDocument bool If true, creates an entity document. Otherwise, just gives a reference to the entity code
 
loadPluginsContent
⚠️ For internal use
Process entity template blocks with plugins. The method returns the content processed by plugins.
$content string Content to be processed by plugins
$entity RootEntityInterface The entity for which we process the content block
$blockType string Content block type. @see BaseTemplatePluginInterface::BLOCK_*
 
printEntityCollectionAsList
Outputting entity data as HTML list
⚠️ This function initiates the creation of documents for the displayed entities
$rootEntityCollection RootEntityCollection Processed entity collection
$type string List tag type (<ul>/<ol>)
$skipDescription bool Don't print description of this entities
$useFullName bool Use the full name of the entity in the list
 
drawClassMap
Generate class map in HTML format
⚠️ This function initiates the creation of documents for the displayed entities
$classEntityCollections ClassEntityCollection The collection of entities for which the class map will be generated
 
getClassMethodsBodyCode
Get the code of the specified class methods as a formatted string
$className string The name of the class whose methods are to be retrieved
$methodsNames array List of class methods whose code needs to be retrieved
 

Last page committer: fshcherbanich <[email protected]>
Last modified date: Sat Oct 28 11:03:31 2023 +0300
Page content update date: Mon Nov 06 2023
Made with Bumble Documentation Generator