# Base Page Template
BasePageTemplate.php is responsible for rendering Twig templates in a PHP application. It includes methods for setting the template, processing data before rendering, and rendering the template with the provided data.
# Twig Filters
# parse_token
This filter is used to replace placeholders in strings with their corresponding values from the $this->dangerData array.
It allows you to pass a string containing \{{ token }\} placeholders, and the filter will replace these placeholders with the actual values from $this->dangerData.
Example
{{ 'Hello, {{username}}!' | parse_token }}
If username is a token in $this->dangerData, this will output the actual username.
# group_by
The group_by filter allows you to group an array of items by a specified key, supporting both associative arrays and object properties. This is particularly useful for categorizing data in Twig templates.
- The function initializes an empty associative array
$grouped. - It splits the
$keyby.to support nested keys. - It iterates over each
$itemin$items:- Traverses nested keys (if applicable) to retrieve the grouping value.
- If the key exists, it extracts the value; otherwise, assigns
null. - Adds the item to the corresponding group in
$grouped.
- Returns the
$groupedarray.
Notes
- Supports both arrays and objects.
- Allows grouping by nested keys using dot notation (
'user.role') - This would group items based onuser.role, assuminguseris an object or associative array. - If a key does not exist in an item, it will be grouped under
null.
Example
{% set grouped_items = items | group_by('category') %}
If items is an array of objects or associative arrays containing a category key, this filter will group them based on that key.
# Parameters
$key(string): The key or nested key (dot notation supported) used for grouping.