-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typecasting docs
Closed
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
date
filter issues (Issues around using Wild mode #38, Type checking strictness #40)markdownify
for jekyll (Add markdownify #36, Add markdownify #37)number_of_words
for jekyllsort
slugify
array_to_sentence_string
jsonify
xml_escape
,cgi_escape
anduri_escape
int
,float
,str
andbool
as both filters and globals for all modes (Type checking strictness #40)