New issue

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

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

Already on GitHub? Sign in to your account

Concat string with integer #314

Closed
Txuritan opened this Issue Aug 6, 2018 · 5 comments

Comments

2 participants
@Txuritan
Contributor

Txuritan commented Aug 6, 2018

It appears that you aren't able to concat a string with an integer. Not sure if this was intentional but the only way around it I've found was to send a vector of integers (basically replacing the range function).

What im trying to do:

{% for page in range(start=1, end=comic.pages) %}
<a href={{ "/c/" ~ page }}>Link</a>
{% endfor %}
@Keats

This comment has been minimized.

Show comment
Hide comment
@Keats

Keats Aug 6, 2018

Owner

The string concat was left intentionally simple to start with. It can be improved or for your usecase we could also add a as_str filter to convert other values into string.

Owner

Keats commented Aug 6, 2018

The string concat was left intentionally simple to start with. It can be improved or for your usecase we could also add a as_str filter to convert other values into string.

@Txuritan

This comment has been minimized.

Show comment
Hide comment
@Txuritan

Txuritan Aug 6, 2018

Contributor

I think a as_str filter would be better, to work around this I created a function that expands the number into a Vec<String>. This then causes a problem with if statements due to the type difference and I really don't was to pass in a separate Vector just for that.

Contributor

Txuritan commented Aug 6, 2018

I think a as_str filter would be better, to work around this I created a function that expands the number into a Vec<String>. This then causes a problem with if statements due to the type difference and I really don't was to pass in a separate Vector just for that.

@Keats

This comment has been minimized.

Show comment
Hide comment
@Keats

Keats Aug 6, 2018

Owner

I also think the as_str filter is better: the main reason I don't want to allow concatenating different types is to avoid at render time errors like "/c/" ~ page where page would be an object and you would get/c/[object]or something. With theas_str` filter, it could still happen but the user has to convert it to str explicitely first.

I'll take a PR for it, it seems pretty simple to implement

Owner

Keats commented Aug 6, 2018

I also think the as_str filter is better: the main reason I don't want to allow concatenating different types is to avoid at render time errors like "/c/" ~ page where page would be an object and you would get/c/[object]or something. With theas_str` filter, it could still happen but the user has to convert it to str explicitely first.

I'll take a PR for it, it seems pretty simple to implement

@Txuritan

This comment has been minimized.

Show comment
Hide comment
@Txuritan

Txuritan Aug 6, 2018

Contributor

How should I handle maps and vectors, I was thinking of using the join filter for vectors but I'm not sure what I should do for maps.

Contributor

Txuritan commented Aug 6, 2018

How should I handle maps and vectors, I was thinking of using the join filter for vectors but I'm not sure what I should do for maps.

@Keats

This comment has been minimized.

Show comment
Hide comment
@Keats

Keats Aug 6, 2018

Owner

Tera already has a way to transform values into str (https://github.com/Keats/tera/blob/master/src/context.rs#L93-L115) just use that one for consistency.

Owner

Keats commented Aug 6, 2018

Tera already has a way to transform values into str (https://github.com/Keats/tera/blob/master/src/context.rs#L93-L115) just use that one for consistency.

@Keats Keats closed this Sep 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment