Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

0.7.2 #41

Merged
merged 14 commits into from
Oct 19, 2021
Merged

0.7.2 #41

merged 14 commits into from
Oct 19, 2021

Conversation

pwwang
Copy link
Owner

@pwwang pwwang commented Oct 13, 2021

Comment on lines +35 to +54
## Typecasting

You are able to do the following in ruby liquid:
```liquid
{{ "1" | plus: 1}} # 2
```
However, this is not valid in liquidpy. Because the template is eventually compiled into python code and the type handling is delegated to python, but "1" + 1 is not a valid python operation.

So you have to do typecasting yourself:
```liquid
{{ "1" | int | plus: 1 }} # 2
```

In order to make it work, extra filters `int`, `float`, `str` and `bool` are added as builtin filters. They are also added as globals in order to get this work:
```liquid
{% capture lst_size %}4{% endcapture %}
{{ 2 | at_most: int(lst_size) }} # 2
```

See also: https://github.com/pwwang/liquidpy/issues/40
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typecasting docs

@pwwang pwwang mentioned this pull request Oct 13, 2021
@pwwang pwwang merged commit 6c3705f into master Oct 19, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant