Type casting #46
Replies: 6 comments 8 replies
-
Are you using the standard mode? Could you share the python code how you call and render your template? |
Beta Was this translation helpful? Give feedback.
-
Hey @pwwang! We're running it in wild mode with python in the https://github.com/frikky/shuffle project, where this issue shows up. The code that runs it all can be found here: https://github.com/frikky/Shuffle/blob/581f97be8029da91ecd43c64abe1359ca1cb5a29/backend/app_sdk/app_base.py#L1767 Hope it helps! :) |
Beta Was this translation helpful? Give feedback.
-
@frikky Thanks for providing the information. It is helpful. We didn't implement the https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.reverse It returns an iterator, instead of a list. If you want a list: >>> from liquid import Liquid, defaults
>>> defaults.MODE = 'wild'
>>> defaults.FROM_FILE = False
>>> Liquid("{{x | reverse}}").render(x=[1,2,3])
'<list_reverseiterator object at 0x7ff91960c880>'
>>> Liquid("{{x | reverse | list}}").render(x=[1,2,3])
'[3, 2, 1]' |
Beta Was this translation helpful? Give feedback.
-
Assume it is solved. Closing. |
Beta Was this translation helpful? Give feedback.
-
Thanks! Parsing straight to | list will indeed be our goto explainer for now. Our docs are coming along btw. Here's an extensive list of what we aim to implement and use: Liquid docs. We will also add examples of each and every one of them long-term. Quick Q about strings: How do you think we could solve the problem of e.g. running something with a filter, but the data is not a string? I'd ideally like to see some kind of auto-casting system, where it assumes something is a string (and e.g. adds the quotes itself), without the need of perfect information left of the pipe. Just wondering how that could be implemented well, as I'm not a parser expert ;) |
Beta Was this translation helpful? Give feedback.
-
So here it's a little bit confusing. For example: out = Liquid("{{ x | plus: 1}}").render(x=1)
# out == "2"
# isinstance(out, str) Are you talking about auto-casting out = Liquid("{{ x | plus: 1}}").render(x="1")
# TypeError: can only concatenate str (not "int") to str |
Beta Was this translation helpful? Give feedback.
-
When trying to reverse this JSON
[
{
"Key": "2",
"A": "B"
},
{
"Key": "1",
"A": "B"
}
]
array we get this error [<list_reverseiterator object at 0x3eb14f722f70>]
Beta Was this translation helpful? Give feedback.
All reactions