PhpStorm and Fluid: namespace 'f' is not bound

Hello there,
Using PhpStorm 2019.1.3.
How to fix this ‘namespace ‘f’ is not bound’ error message?

Sincerely,
Alex!

Hey,

to help your IDE, you should declare the html namespace on the root element of your template (or partial). It is a good practical measure, to wrap all your partials and templates in a <html> tag. First of all, all those files will become valid XML documents (with a single root element) and second you can help your IDE help you with autocompletion, if the namespaces are registered correctly via an XSD (see https://flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/Templating.html#xsd-schema-generation). Also that html tag will not be rendered in the output, since the templates and partials will only render the specific <f:section>s.

<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
      xmlns:f="http://typo3.org/ns/fluid/ViewHelpers">

<f:layout name="Default" />

<f:section name="...">
...

</html>

See also
https://flowframework.readthedocs.io/en/stable/TheDefinitiveGuide/PartIII/Templating.html#namespaces

Hey Alexander,

Tnx for reply and help.

Neos docs tell us the following:

A namespace linking f to \Neos\FluidAdaptor\ViewHelpers is imported by default. All other namespaces need to be imported explicitly.

Either I don’t understand English or some additional actions has to be done to make this {namespace f=Neos\FluidAdaptor\ViewHelpers} work as advertised when placed as a first line in fluid template. If you or someone else knows the solution for this approach - please, share it here.

Before posting Q here, I tried approach from the official Neos docs and it does not work by default as one would expect.

Defining namespace with XML does the trick of removing warnings, but I do not get auto-completion. Probably because http://typo3.org/ns/fluid/ViewHelpers these days just returns 404.

Unfortunately, I could not find valid schema for latest Fluid which comes with Neos. If anyone can share it here - please do so or provide download link.

Thanks in advance.
Alex

Either I don’t understand English or some additional actions has to be done to make this {namespace f=Neos\FluidAdaptor\ViewHelpers} work as advertised

No worries. The {namespace=...} import syntax is the old style and it only works for making the ViewHelpers work correctly in Fluid itself, but you’d need a very specialized tool or a plugin for your IDE to make it understand this syntax. Hence why the xml namespace import was added way back - it achieves the same and also a bit more, because every IDE that understands XML will understand that syntax.
So generally, you can replace all {namespace=...} imports and for avoiding the error highlighting, you should also import the default f namespace. This one works without explicit import for Fluid itself, but again your tools don’t know about it, unless you import it.

Defining namespace with XML does the trick of removing warnings, but I do not get auto-completion. Probably because http://typo3.org/ns/fluid/ViewHelpers these days just returns 404.

The URL itself isn’t really important. I think it never really resolved to anything helpful/different than 404. It’s basically just a unique name for the namespace. The important bit, to get the autocomplete working, is to have an XSD schema somewhere linked to that unique name (as briefly explained in Templating — Flow Framework 8.3.x documentation). For this you can generate the schema via the command line

./flow documenation:generatexsd TYPO3Fluid\\Fluid\\ViewHelpers --xsd-namespace http://typo3.org/ns/fluid/ViewHelpers 
--target-file ./typo3.fluid.xsd
./flow documenation:generatexsd Neos\\FluidAdaptor\\ViewHelpers --xsd-namespace https://neos.io/ns/fluid/ViewHelpers --target-file ./neos.fluidadaptor.xsd

There are two files, because as of now, there is both Typo3Fluid standalone, with a set of basic ViewHelpers and then there is the Neos FluidAdaptor with a couple of additional ViewHelpers.
This complicates things quite a bit, because you’d need to merge those into a single file first to have both set of ViewHelpers available under a single xml namespace.

After that you need to tell your IDE where it finds the XSD file for a given unique name, this depends highly on the IDE so there is no general documentation for that. Here is some base information for PHPStorm: Schemas and DTDs | PhpStorm Documentation

I think we should provide a better documentation and maybe an easier setup for the schema validation somehow, since it’s a great dev experience issue. We could maybe automatically generate the schemas on release and make them available somewhere online, so they can be used with the f:schemaLocation tag. I’ll bring that up with the team.

1 Like

Alexander, thanks for detailed answer.

The {namespace=...} import syntax is the old style and it only works…

The funny moment is that Neos.Kickstarter creates Fluid templates with {namespace} imports.

As for Schema.
For some strange reason on Windows machine I get this for Neos.FluidAdaptor:

An error occurred while trying to generate the XSD schema:
No ViewHelpers found in namespace "Neos\FluidAdaptor\ViewHelpers"

And similar for Typo3 command.

Still, on Ubuntu schema generation for Neos.FluidAdaptor went fine, but same error as above for Typo3.

By accident I found schema for TYPO3Fluid and added/refreshed elements from NEOS to it and now things show in PhpStorm just fine.

I would attach this schema file here, but it is not allowed.

I think we should provide a better documentation…

You are absolutely right when you say better documentation. This is the KEY area that requires significant attention. Lack of samples, outdated information and so on. All of this very much limits the desire of newcomers to explore and learn product. One of such EMPTY area in documentation is how to properly configure routes and other aspects for plugins that are added from within the CMS backend.

Thanks for help.

That’s a good point and could probably be improved, so that the default is the xml namespace syntax.

You are absolutely right when you say better documentation .

We’re working on it :slight_smile: docs.neos.io is our new go-to reference for Neos CMS that the documentation guild is working on. I’d even say, doing good documentation is harder than building a feature. Still, it’s always harder for a knowing insider to see the stumbling stones a newcomer has, when reading documentation. So if you have any hints on what can be improved, what isn’t clear or needs more attention, give us a heads up here or on slack #guild-documentation - we’d highly appreciate it :slight_smile:

Sure, tnx

FYI: I started an issue to work on that topic and the first step is to get rendering of the TYPO3 Fluid ViewHelper schemas working again, which seems indeed broken for some time now, resulting in the

An error occurred while trying to generate the XSD schema:
No ViewHelpers found in namespace “Neos\FluidAdaptor\ViewHelpers”

Thanks for bringing it up :slight_smile:

Thank you.