-
Notifications
You must be signed in to change notification settings - Fork 4
Additional features Twig
Returns the current URL including the request URI.
{{ current_url() }}Parses the current URL into an associative array containing scheme, host, path, query and fragment keys.
{% set parsed = parse_url(current_url()) %}
{{ parsed.scheme ~ '://' ~ parsed.host }}Generates a URL for the given route name with optional data and query parameters.
{% set url = path_for('common:main') %}
<a href="{{ url }}">Main</a>Generates a full URL for the given route name with optional data and query parameters.
{% set url = full_url_for('common:main') %}
<a href="{{ url }}">Main</a>Returns the base URL without a trailing slash.
{{ base_url() }}Checks if the current path matches the given route name and data.
{% if is_current_path('product', {'id': 123}) %}
<p>Current page is product with ID 123</p>
{% endif %}Returns the current path on given URI. If $withQueryString is true, includes the query string.
{{ current_path() }}Generates a input using the specified type and name with optional arguments.
{{ form(type, name, {'class': ['form-control']}) }}Retrieves the value of a PHP constant by reference or returns a default value if it doesn't exist.
{% set types = constant('/App/Domain/Casts/Catalog/Attribute/Type::LIST') %}Prints variables for debugging purposes.
{{ pre(user) }}Performs a regular expression replacement on the given subject string.
{% set text = "Hello, World!" %}
{% set result = preg_replace('/World/', 'Twig', text) %}
{{ result }}Counts the number of elements in an array or iterable object. Returns false for non-countable objects.
{% set arr = [1, 2, 3] %}
{{ count(arr) }}Formats a date using the specified format. Default format is 'j-m-Y, H:i'.
{% set now = df() %}Converts PHP date format to Moment.js format.
{{ dfm('Y-m-d') }}Creates a new collection from an array or existing Collection.
{% set collection = collect([1, 2, 3]) %}Returns the path without the current page number if present.
{{ non_page_path() }}Returns the current page number from the URL path.
{{ current_page_number() }}Returns the current query string or modifies it by setting a key-value pair.
{% set url = full_url_for('product', {'id': 123}) %}
{{ current_query('page', 2) }}Checks if the current page number matches the given number.
{% if is_current_page_number(1) %}
<p>This is page 1</p>
{% endif %}Builds a query string from an optional URL and parameters array.
{% set url = 'https://example.com' %}
{% set params = {'q': 'search', 'page': 1} %}
{{ build_query(url, params) }}Encodes a string using Base64 encoding.
{{ base64_encode('Hello, Twig!') }}Decodes a Base64-encoded string. Optional strict flag controls the behavior on invalid input.
{% set encoded = 'SGVsbG8sIFdvcmxkIQ==' %}
{{ base64_decode(encoded) }}Encodes a PHP value into JSON format.
{% set obj = {'name': 'John', 'age': 30} %}
{{ json_encode(obj) }}Decodes a JSON string into a PHP value.
{% set json = '{"name": "John", "age": 30}' %}
{{ json_decode(json) }}Cache management functions for Twig extension.
cache_put('my_key', 'Hello, Twig!', 3600)Converts a file size to human-readable format (e.g., KB, MB).
{{ convert_size(2048) }}Generates a QR code image for the given value with optional size and margin.
{{ qr_code('https://example.com') }}Fetches files based on criteria, order, limit and offset. Uses FileService.
{% set files = file({'ext': 'webp'}, ['date' => 'desc']) %}Fetches pages based on criteria, order, limit and offset. Uses PageService.
{% set pages = page({'title': 'The Hitchhiker's Guide to the Galaxy'}) %}Fetches publication categories based on public status (optional).
{% set category = publication_category(true) %}Fetches publications based on criteria, order, limit and offset. Uses PublicationService.
{% set publications = publication([], ['date' => 'desc']) %}Fetches references by type or all types (if null). Optional pluck feature returns a collection of key-value pairs.
{% set length_class = reference(ReferenceType::LENGTH_CLASS) %}Returns the value of a named configuration parameter or default value (if provided).
{{ parameter('common_homepage') }}Fetches guest book rows based on order, limit and offset. Uses GuestBookService.
{% set guestbooks = guestbook(['date' => 'asc']) %}Fetches catalog attributes based on criteria and optional order. Uses CatalogAttributeService.
{% set attributes = catalog_attribute() %}Fetches catalog categories based on criteria and optional order. Uses CatalogCategoryService.
{% set categories = catalog_category() %}Fetches catalog products based on criteria, order, limit and offset. Uses CatalogProductService.
{% set products = catalog_product() %}Returns the product price type based on user context.
{% set priceType = catalog_product_price_type() %}catalog_product_popular(int $limit = 10, string $type = \App\Domain\Casts\Catalog\Product\Type::PRODUCT): Collection
Fetches popular products by count of orders. Uses CatalogOrderProduct database query.
{% set popularProducts = catalog_product_popular() %}Saves or returns the list of viewed product UUIDs in session.
{% set viewedProducts = catalog_product_view('UUID') %}Calculates the dimensional weight of a product based on its dimensions and configuration constants.
{{ catalog_product_dimensional_weight([product = null]) }}Fetches catalog orders based on criteria, order, limit and offset. Uses CatalogOrderService.
{% set orders = catalog_order() %}Fetches users based on criteria and optional order. Uses UserService.
{% set users = user() %}Fetches user groups based on criteria and optional order. Uses UserGroupService.
{% set userGroups = user_group() %}Information
Usage
For developers