Add support for twig templates

Twig is a very commonly used templating library for PHP. It would be nice if the HTML analyzer understood Twig tags. Currently, these tags can cause errors, for example:


	.doc_manager {
		background-color: {{ systemUser.get('background-color') }}

Will lead to complaints about systemUser.get('background-color') being an ‘unexpected unknown property’, even though it would be properly replaced at runtime.

Hi,

‘unexpected unknown property’, are we talking about CSS rule here? (you can check that by rule key prefix)

Yes, it’s rule css:S4654

So the file where you have those FPs is a php file or html? Could you show the full file, minimal file reproducing this FP?

Official documentation says It doesn't have a specific extension, .html or .xml are just fine, but normally I have seen twig templates as .html.twig.

Hi everyone, this was the only post I found on the forum about support for twig files. Is this still a feature request, as we also have twig files with the ‘html.twig’ extension that are not being recognized. I cannot figure out whether this is because either these files are simply not supported, or because the scanners are simply not incorporating the files with those extensions?

Is there a way to tell the html/css scanners to also incorporate ‘html.twig’ files perhaps?

Any tips much appreciated!

Hello @validaide-mark-bijl and welcome to the community!

Unfortunately, we do not support parsing and analyzing twig file at the moment.
However, we have this item on our agenda. So stay tuned, we will hopefully provide this feature soon.

Best,
Nils

1 Like

Hey Nils, thanks so much for the quick and clear response! Will definitely stay tuned then :slight_smile: We are running Sonar in our GitHub PR build for our Symfony / PHP applications and libraries to ensure our team stay sharp, and just being able to detect e.g. duplicate code would already be a great advantage!

Cheers,
Mark