Closed didibus closed 1 year ago
Until there's a standard feature to do it, for those looking, you can use the following:
(require '[selmer.filter-parser :as htmlp])
(require '[selmer.parser :as html])
(defn resolve-selmer-args
[args context-map]
(map #(if (htmlp/literal? %)
(htmlp/parse-literal %)
(html/render % context-map)) args))
Now if you give the args passed to add-tag!
to resolve-selmer-args
it'll return them resolved, meaning if they themselves contain variables with or without filters, or tags, those will get processed first, and you'll get the value out of them as the arg.
Ah yeah, that would be the best approach. It would probably be reasonable to add the above helper function to help with resolving variables in custom tags. Would you like to do a PR for that?
I can make one in the next few days.
Sounds like a plan. 👍
In a custom tag, any way that I can resolve variables?
Template:
The custom tag gets "{{game.push.img}}" as the arg, but I would want this resolved and get the value it refers too instead.