sebastienros / fluid

Fluid is an open-source .NET template engine based on the Liquid template language.
MIT License
1.35k stars 173 forks source link

Should we be able to "namespace" filters? #425

Open deanebarker opened 2 years ago

deanebarker commented 2 years ago

Should we be able to refer to "namepsaced" filters that include dots?

We can register them. This works fine:

TemplateOptions.Default.Filters.AddFilter("html.extract_body", ExtractHtmlBody);

However, you get a ParseException if you try to use it:

{{ html_string | html.extract_body }}
End of tag '}}' was expected at (1:22)

This is not technically a "Liquid" syntax thing, since this sits in the intersection between the language and the underlying implementation. I didn't find any "namespaced" filters in Liquid proper, but I also didn't see anything that prohibited them.

Scriban uses namespaces in all cases. Ex: string.append

I don't want to go that far -- I think "simple" filter names should be the default. But in the case of a set of closely related filters, it might be helpful.

hishamco commented 2 years ago

This is not technically a "Liquid" syntax thing

If it's not, so this may introduce extra overhead in parser

This could be cool if the editor or IDE support auto completion, otherwise you will see that you write everything yourself ;)

sebastienros commented 2 years ago

Dots are not supported in filter names, in Liquid. - and _ are however. I am not opposed to having this being a flag, like other extensions to the language. The implementation would be to accept dots in the parser that is used for identifiers (in filters only) here https://github.com/sebastienros/fluid/blob/91aa570a5f0ad0f145ec03cec9d6d75b8ce980c1/Fluid/FluidParser.cs#L170