<?php
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class BlockTitleExtension extends AbstractExtension
{
public function getFilters(): array
{
return [
new TwigFilter('block_title', [$this, 'blocktag']),
];
}
public function blocktag($url, $op = 'sec'): String
{
$url = explode('**', $url);
$text = '';
if( $op == 'sec' ){
foreach ($url as $i => $v) {
if( $i % 2 == 0){
$text .= $v;
}else{
$text .= "<strong>{$v}</strong>";
}
}
}else{
foreach ($url as $i => $v) {
if( $i % 2 == 0){
$text .= "<strong>{$v}</strong>";
}else{
$text .= $v;
}
}
}
return $text;
}
}