drupal 8 twig filters
//Create file: ctwigfilters.services.yml
services:
ctwigfilters.twig_extension:
arguments: ['@renderer']
class: Drupal\ctwigfilters\TwigExtension\MyHumanize
tags:
- { name: twig.extension }
//file: ctwigfilters/src/TwigExtension
<?php
/**
* Created by PhpStorm.
* User: Zhilevan
* Date: 1/9/18
* Time: 23:38
*/
namespace Drupal\ctwigfilters\TwigExtention;
class MyHumanize extends \Twig_Extension {
public function getFilters()
{
return [ new \Twig_SimpleFilter('myhumanize', array($this, 'myHumanize'))];
}
public function getName()
{
return 'ctwigfilters.twig_extension';
}
public static function myHumanize($string)
{
$str = trim(strtolower($str));
$str = preg_replace('/[^a-z0-9\s+]/', '', $str);
$str = preg_replace('/\s+/', ' ', $str);
$str = explode(' ', $str);
$str = array_map('ucwords', $str);
return implode(' ', $str);
}
}
// in twig file
{{ your-variable | myhumanize }}
Also in PHP:
- extract data from api callback php
- count string char php
- $this- attribute laravel
- PHP Html-Optimizer on github
- divided by 3 php
- date and time function in php
- display_errors php.ini
- array_column in php
- daye in php
- Impossible de trouver le paquet php-gettext
- catch multiple exception php
- always getting error Your username or password is incorrect. in cakephp login in xampp
- count characters php
- digitalocean php as text
- Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes
- clear docker cache
- datetime manual date format
- PHP @ errors
- change timestamp format php
- cambiar entre versiones de php linux
- Increase the PHP memory limit
- array_key_exists contains string
- check type of object in php
- find first occurance of sentence in a string php