Allow expressions as used in twig, e.g. {{ url('<current>') }}. Use case is current url but also dates like "now". There is no variable that needs to be selected here.

Comments

fago created an issue. See original summary.

tr’s picture

Issue summary: View changes
tr’s picture

How do you think this should work?

I think it may be better to use a syntax like {{ | url('<current>') }}. Note that I've used the '|' as a prefix. This way, functions like url() could be defined as TypedDataFilter plugins. The parser can already recognize data filters as the element of the token after the pipe. (I see you chose the "Data filters" component for this issue ...)

The only obstacle is to ensure that when PlaceholderReplacement parses the token, it allows the variable to be missing. Right now this syntax will fail, but it seems to be only a parsing issue that's easily fixed. . (In fact, I already have written a 'url' data filter which works exactly like this, but I currently need to use a dummy variable like node.title.value before the pipe so that I don't get a syntax error.)

If we don't treat functions like url() as TypedDataFilter plugins, the problem with {{ url('<current>') }} becomes how can this be extended to add new functions? I think maybe a whole new plugin type would be required. And then there would still be some ambiguity when parsing the token, as we won't know whether we're looking at a context variable or one of these new plugins.

tr’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
tr’s picture

Version: 2.0.x-dev » 2.1.x-dev