Using and Mastering Cookiecutter Transcripts
Chapter: Creating Cookiecutter templates
Lecture: Concept: Dependent values

Login or purchase this course to watch this video and the rest of the course contents.
0:01 So let's look at the concepts behind this dependent value thing. So if we come over here and we run the Cookiecutter template template
0:08 that's the one that generates Cookiecutter templates for us, and we run it, it asks a bunch of questions: what's your name,
0:14 what's your email and so on, and then it gets to this point where it asks
0:17 what's the project name, and I just entered whatever I feel like, greatest thing ever;
0:21 and that's cool, but the next question is where things get interesting, right, the project slug is actually a url style, a directory style name,
0:29 that incorporates that, so cookiecutter-greatest-thing-ever, and then it goes on to ask us the rest of the questions.
0:37 So we saw that the project name is actually adapted over to here. So, how do they do that, they did that with Jinja expressions,
0:45 and that's because this cookiecutter.json is more powerful and more expressive than it initially seems,
0:52 so you can see we have project_name, and we can take that project name and apply it as a Jinja template expression, so we're going to take it
1:00 and we're going to put it right there, remember, it's always {{cookiecutter. }} and then it's the whole thing, right, it's whatever it's entered there
1:08 we can work with this, so cookiecutter.project_name and now we can additional Python code on this. Lowercase it, strip it, replace spaces with dashes,
1:17 as you saw, it maybe could use a little bit more work but not not bad at all. And then it just goes on to ask the remaining questions.
1:24 So you could do very powerful and interesting things in these default values. And I find that to be super helpful, if it asks me
1:33 what the name is and then what the slug is, maybe I don't even really totally understand what the slug means,
1:38 I don't understand that that's actually the directory name which results in being the name of the template I am building with this template builder,
1:44 but the fact that it does this for me, even though it's like one line of sort of expression Python bits here it's super helpful to me
1:50 as a consumer of this template. To make sure that I fall into the pit of success, I don't enter values that are not allowed, and so on.
1:58 You'll see that when we get to the hook section, we could actually do way more powerful stuff than this,
2:03 but this is already really helpful because it provides the default rather than just validating what we put in,
2:09 it actually provides an adapting default, which is great.


Talk Python's Mastodon Michael Kennedy's Mastodon