Closed marinbenc closed 7 years ago
I am not so sure Stencil has a contains
filter http://stencil.fuller.li/en/latest/builtins.html#built-in-filters But would love to be wrong :] Oh re-reading you have a custom filter? I'd like to learn more.
we have a custom filter, but looking at Stencil source I'm not sure if if
tags support filters in current version? did you use them before @alisoftware @ilyapuchka ?
Yep, I'm also not sure if Stencil actually supports filters in if
. Using {{ FooBar|country: "Foo" }}
works fine though. Probably we need to file an issue in Stencil repo to improve that. /cc @kylef
I don't think so either.
One workaround would be to use the {% set %}
node I use in SwiftGen (and soon available via SwiftGen/StencilSwiftKit onces we finish the Great Split of SwiftGen) to set it result of the filter into a temporary variable then do the if
on it. Might be a workaround if SwiftGen/StencilSwiftKit comes before any PR on Stencil to support filters in if
nodes.
(Of course in long term supporting filters in if
expressions would indeed be better).
BTW @krzysztofzablocki even if SwiftGen's Great Split isn't finished yet, I think you may already start using https://github.com/SwiftGen/StencilSwiftKit as a pod dependency for Sourcery.
We still have to create an Xcode projet, add the unit tests from SwiftGen for those nodes, configure Travis, Write the documentation, etc… but the podspec already works, so even if it's not yet pushed to trunk you should totally be able to use pod 'StencilSwiftKit', :git => 'https://github.com/SwiftGen/StencilSwiftKit'
already to give it a try :wink:
I didn't realise Stencil did not support custom filters in an if statement. In the Sourcery documentation, there's this line
{% if name|contains: "Foo" %}
- check if name contains arbitrary substring
I guess that confused me.
yeah I think we made assumption it will work (it really should), we mostly use filters on for loops and in those it works :)
With the template
I get the error:
'if' expression error: dangling token
However, when I replace the custom
contains
filter with a built-in operator the file generates normally.Am I doing something wrong?