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.
0:04 So if we come over here and we run the Cookiecutter template template
0:07 that's the one that generates Cookiecutter templates for us,
0:10 and we run it, it asks a bunch of questions: what's your name,
0:13 what's your email and so on, and then it gets to this point where it asks
0:16 what's the project name, and I just entered whatever I feel like, greatest thing ever;
0:20 and that's cool, but the next question is where things get interesting, right,
0:23 the project slug is actually a url style, a directory style name,
0:28 that incorporates that, so cookiecutter-greatest-thing-ever,
0:33 and then it goes on to ask us the rest of the questions.
0:36 So we saw that the project name is actually adapted over to here.
0:40 So, how do they do that, they did that with Jinja expressions,
0:44 and that's because this cookiecutter.json is more powerful
0:48 and more expressive than it initially seems,
0:51 so you can see we have project_name, and we can take that project name
0:55 and apply it as a Jinja template expression, so we're going to take it
0:59 and we're going to put it right there, remember, it's always {{cookiecutter. }}
1:04 and then it's the whole thing, right, it's whatever it's entered there
1:07 we can work with this, so cookiecutter.project_name
1:10 and now we can additional Python code on this.
1:13 Lowercase it, strip it, replace spaces with dashes,
1:16 as you saw, it maybe could use a little bit more work but not not bad at all.
1:20 And then it just goes on to ask the remaining questions.
1:23 So you could do very powerful and interesting things in these default values.
1:28 And I find that to be super helpful, if it asks me
1:32 what the name is and then what the slug is,
1:35 maybe I don't even really totally understand what the slug means,
1:37 I don't understand that that's actually the directory name
1:40 which results in being the name of the template I am building with this template builder,
1:43 but the fact that it does this for me, even though it's like one line
1:46 of sort of expression Python bits here it's super helpful to me
1:49 as a consumer of this template.
1:52 To make sure that I fall into the pit of success,
1:54 I don't enter values that are not allowed, and so on.
1:57 You'll see that when we get to the hook section,
2:00 we could actually do way more powerful stuff than this,
2:02 but this is already really helpful because it provides the default
2:06 rather than just validating what we put in,
2:08 it actually provides an adapting default, which is great.