Rock U - Lava - Assign Statement

Transcribed Video Content

Okay. So now let's look at variable assignment. We've already hopefully looked at filters and hopefully you've gone through some of the tags the if tag and the for tag. Let's look at another tag that helps us define variables within Lava. Now a lot of times, Lava in Lava you're provided variables, they come in, they're passed to your Lava and so you can operate off those, but you can actually assign and create your own, variables. So in this case, we're taking the hour, the current hour from the date object and then we're gonna use that variable in an if statement to just filter through and to say whether it's good morning, good afternoon, or good evening. So this is a a good way of, showing you why you'd create a variable because in this case, we can't have, a filter inside of an if statement. So that's a good reason why we would need to actually go ahead and, define it up here. A lot of other reasons is, , sometimes you're gonna be piping this through multiple different if statements. Sometimes you wanna get maybe a count of how many items are in array. You'll find that you'll often be assigning your own variables. In some cases, you might even be doing that just to kind of simplify or make your your Lava template more readable instead of always piping it through the same thing through five times. You might just make one variable do it once and then use that variable five times. So a lot of times, assignment is actually a great way of cleaning up your templates. But definitely within if statements, they're very valuable because you can't use a filter instead of an if statement. Do check out the lava page for more on on doing the assign and capturing data into variables.