I'm trying to add some images dynamically with Twig. So I defined a new Twig function called setImgService
which basically chechs for a service name and depending on it, it will return some HTML code according to its image.
Function code:
$setImgService = new Twig_SimpleFunction('setImgService', function($serviceName){
switch ($serviceName){
case "Analitycs":
return '<img src="assets/img/analitycs.png">';
case "Hosting":
return '<img src="assets/img/hosting.png">';
case "SEO":
return '<img src="assets/img/seo.png">';
case "Maintenance":
return '<img src="assets/img/maintenance.png">';
case "Your own domain":
return '<img src="assets/img/domain.png">';
case "BackUp":
return '<img src="assets/img/backup.png">';
}
});
// Add function to Twig
$twig->addFunction($setImgService);
But when I use
{{ setImgService('serviceName') }}
It returns HTML code like plain text.
Any help, please?