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
Add a split filter #898
Comments
Thanks for the suggestion. After some thought, I don't think this belongs in Jinja. The example here is being way too clever where data should be the correct type to begin with (this is the general advice I've heard from Ansible devs as well). For example, if you have a list, make it a list of lists to begin with, rather than a list of strings. In full templates where you're not trying to force everything into one expression, or have more control over the data being passed to the template, this becomes much less needed. |
As a counterpoint the project cookiecutter uses jinja and can ask the user to input a comma-separated string in the console when a cookiecutter project is generated. It would be useful to be able to take that input and split on the comma to get a list. |
Why not define your own filter for this inside the cookiecutter code though? |
Let's close all issues and ask people to implement them in their code. |
@nkakouros No need to post passive-aggressive comments. I don't think many people need this filter, so why add it to the core? It's perfectly normal to use Jinja's APIs to register custom filters if you want to use one that is not part of the core. |
Whatever passive aggressive means, my comment was meant as the extreme application of your logic, sth that is often done to highlight the traps or errors in an argument. Do you have statistics about the use of each filter or Jinja feature? I would like to see them too. But I have seen this issue pop up every now and then both here and in other projects that rely on Jinja. Also it is not only the popularity of a feature that matters but also intuitiveness. It is normal to think (I believe) to expect a split filter when there is a join filter. Maintenance overhead for such a filter will be not even minimal while you will support beautiful code, without nested parentheses for advanced users without asking them to cater for custom plugins. Of course the project is not mine to decide, I am just expressing a use case. |
@ThiefMaster For what it's worth, I started to look into that option as well, I'd need to rely on this PR: cookiecutter/cookiecutter#1240 to be able to pull that off. So I'm stuck either way right now. Since there is a |
It could be useful if you wanted to change something in an array like this:
|
This is a followup on the discussion here.
The issue with the
split
method is that is cannot be used withmap
. There are some use cases on the linked page.There is a closed PR that could be used.
Template Code
Your Environment
The text was updated successfully, but these errors were encountered: