drupal 8 twig without multiple
// Without multiple fields
{{ content|without('field_yourfield', 'field_yourfield2') }}
drupal 8 twig without multiple
// Without multiple fields
{{ content|without('field_yourfield', 'field_yourfield2') }}
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 }}
drupal 8 twig without multiple
// Without multiple fields
{{ content|without('field_yourfield', 'field_yourfield2') }}
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 }}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us