How to Fix IntelliJ Namespace Warnings in Fluid Templates

Today, while working on some Fluid templates, once again I came across that irksome namespace warning in IntelliJ. Since I recently found out how to get rid of it, I decided to share this bit of knowhow with you.

Namespace warnings in Fluid templates

These warnings actually make sense to make sure any XML documents you edit contain valid XML namespaces. In Fluid templates for Neos and Flow however, they're usually just annoying. There is a way to get rid of these warnings, by adding an HTML tag with the namespace attribute set to your templates. Just add this snippet of HTML around your Fluid templates or layouts.

<html xmlns:f="" xmlns="" lang="en">

Since templates contain sections and only these are rendered, this shouldn't influence rendering in any way. What about Fluid partials, however? We need a bit of extra logic to add the HTML to partials as well. We're going to make use of the section feature of partials like so.

<!-- YourPartial.html -->
<html xmlns:f="" xmlns="" lang="en">    

<f:section name="partial">

When rendering these partials from a Fluid template or layout, just add the section name to the render tag and your partial will render like before.

<f:render partial="YourPartial" section="partial" />
Namespace warnings in Fluid templates removed

No more namespace warnings - very good so far. What about other namespaces, though? What if you load custom viewhelpers or use the ones from Neos Media or Neos itself instead of only Fluid? There's an easy fix for that as well. You can add as many of the xmlns attributes to the HTML tag as you want, and IntelliJ as of now doesn't validate them - it just checks that the namespace is bound. While this may feel a bit hacky, and is technically not valid XML, it does remove the warnings for custom namespaces as well.

Adding another xmlns attribute

Using this technique, you shouldn't be bothered by unbound namespace warnings again! You could even define a live template or file template to save you some typing. Enjoy!