Download the PHP package gupalo/twigext without Composer

On this page you can find all versions of the php package gupalo/twigext. 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 twigext

Twig Ext

Twig Extensions

Usage

composer require gupalo/twigext

Symfony

Add to config/services.yaml

Gupalo\TwigExt\:
    resource: '../vendor/gupalo/twigext/src/TwigExt'
    tags: ['twig.extension']

You can customize FormatExtension:

Gupalo\TwigExt\FormatExtension:
    bind:
        $translations:
            span: div
            format-date-zero: text-warning
        $wrapSpan: false

ArrayExtension

uniq(items, keepKeys = false)

array_unique

If keepKeys = false (default) then array_values of the result.

max_value(items, field)

Max of field values of items.

Uses PropertyAccessor so it may be object with properties

max_ratio_value(items, field, field2)

Max of field/field2 values of items.

Uses PropertyAccessor so it may be object with properties

sum_value(items, field)

Sum of field values.

Uses PropertyAccessor so it may be object with properties

array_sum(items)

https://www.php.net/manual/en/function.array-sum.php

EncodingExtension

base64_encode

https://www.php.net/manual/en/function.base64-encode.php

base64_decode

https://www.php.net/manual/en/function.base64-decode.php

md5

https://www.php.net/manual/en/function.md5.php

ExitExtension

exit

Throw TwigExitException. You app should intercept and process it.

FormatExtension

int

float

money

percents

date_full

date_short

date_noyear

JsonExtension

json_decode

json_decode array.

If there will be invalid string then there will be no error, just an empty array.

ProgressExtension

progress_class

progress_percents

progress_int

progress_float

RandomExtension

random_hour, random_day

Pseudorandom. Default 1..100.

{% if random_day() <= 40 %}40% chances to see this text{% endif %}
{% if random_day() > 40 %}otherwise, you'll see this text{% endif %}

{% if random_day() <= 20 %}
    20% chances
{% else if random_day() <= 65 %}
    45% chances
{% else %}
    35% chances
{% endif %}

{% if random_day() <= 20 %}
    {% set content %}
        {% include '_elements/test1' ~ app.request.uri ~ '.html' %}
    {% endset %}
{% else if random_day() <= 65 %}
    {% set content %}
        {% include '_elements/test2' ~ app.request.uri ~ '.html' %}
    {% endset %}
{% else %}
    {% set content %}
        35% chances
    {% endset %}
{% endif %}

random_day returns same number same day, random_hour - same number same hour.

Optional params:

random_item

Pick one random item value from items

{{ random_item(['aaa', 'bbb', 'ccc']) }}

random_items

Pick several random items from items

Echo 2 random items: "aaa, bbb" or "aaa, ccc", or "bbb, ccc", or "bbb, aaa", or "ccc, aaa", or "ccc, bbb".

{{ random_items({'k1': 'aaa', 'k2': 'bbb', 'k3': 'ccc'}, 2)|join(', ') }}

Same but preserve keys

{{ random_items({'k1': 'aaa', 'k2': 'bbb', 'k3': 'ccc'}, 2, true)|json_encode }}

If items is empty then default value (4th argument) is returned: "ouch" in example. Default - [].

{{ random_items({}, 2, true, 'ouch')|json_encode }}

If you ask for more items that it exists in items then all items will be returned but shuffled: "aaa, bbb" or "bbb, aaa"

{{ random_items({'k1': 'aaa', 'k2': 'bbb', 1000)|join(', ') }}

StringExtension

truncate(s, length = 100)

Limit length of the string. If it's longer - add &hellip; (...)

underscore(s, character = '_')

Change text to underscore

{{ 'CamelCase? ok'|undersore }}

Will return camel_case? ok

mask_password(s)

Keep only first 3 letters and mask next ones

{{ 'mySuperPassword'|mask_password }}

Will show myS*****.

safe_title(s)

Prepare value to be inserted into HTML attribute.

<a title="{{ unsafe_text|safe_title }}">hello</a>

ucfirst(s)

https://www.php.net/manual/en/function.ucfirst.php


All versions of twigext with dependencies

PHP Build Version
Package Version
Requires php Version >=8.4
gupalo/arrayutils Version ^1.11
gupalo/dateutils Version ^1.20
gupalo/json Version ^1.4
symfony/property-access Version ^7.4|^8.0
twig/twig Version ^3.22
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 gupalo/twigext contains the following files

Loading the files please wait ...