fluid icon indicating copy to clipboard operation
fluid copied to clipboard

Should we be able to "namespace" filters?

Open deanebarker opened this issue 4 years ago • 2 comments

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.

deanebarker avatar Dec 10 '21 02:12 deanebarker

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 ;)

hishamco avatar Dec 10 '21 07:12 hishamco

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

sebastienros avatar Jan 03 '22 00:01 sebastienros