Rock U - Lava - Filters

Transcribed Video Content

Okay. So let's look at filters. Filters are one of the basic concepts of Lava and they give you a lot of power and a lot of capabilities. So let's just walk through and look at some of these filters. Okay. So we saw this one from our what is lava video. But basically, this is, taking some data person and, just presenting it into a template. Okay? So at this point, we don't have any filters. We're just starting with the very basic example and we'll kind of move from here looking at how we can apply filters to this. So again, we take our data, we take our template and we get our results. Okay? So let's look at some basic filters. In this case, we have the same data. We have basically the same template except this time we're running it through a filter. Okay? And we use this little, vertical bar which we call pipe, to run it to the filter. So you're basically taking this data and you're piping it through this filter. Okay. So you kind of kind of think of it as a plumbing concept. The data comes comes this way, goes in through the pipe and it goes through our filter, which in this case is up case. And all up case does is it makes it upper case. And so in this example, we can see that Ted is now all upper case. Okay? So that's a very very basic, text filter. Now, know it's possible. You can do a lot of crazy things with filters. So in this case, we have this, data of workflow and the workflow has a term called request. So we're gonna say there are many and we're gonna take the the data out of the workflow term and we're gonna pipe it through a filter called pluralize. That's gonna do exactly what it sounds . It's gonna pluralize that word and then we're gonna pipe it again through another filter called down case. And that's gonna do the opposite of up case. It's gonna make everything lower case. Okay. So in this case, we're just showing you you can chain these filters together and you can keep piping them through. Again, this is where the plumbing concept comes in really handy because we're just hooking these pipes together so that the the data just kind of flows through pluralized then goes into down case and then was put into our template. Now, we're seeing here in this other example where it says man, we're not passing it data anymore. Now, we're actually passing it the literal, string of man. Okay? So it's not there's no variable here. We're just saying, hey, take the text of man, pluralize that. This is just showing you that the pluralize is actually really powerful. So it knows how to take man is not the pluralize. Man is not man's, it's men. And so it just showing off that that is smart enough to do that. And again, it knows how to pluralize things goose to geese. Okay. So pluralize is actually really powerful. But the key in this one is is how we've piped through two different filters. So let's look at some more text filters here. Now, there's a lot of text filters but here's just a few examples. So we already saw up case down case. We can do title case which does exactly what you would think it would do and makes it kind of in the way that a title would be on a page or a book. Pluralize, we saw that. Singularize is the opposite of pluralize. Size would return, how many characters are in the string. Strip HTML. So if your string had HTML in it, it would remove any HTML. This is good if you need to present something to the user and you don't want any of that formatting. You can take the formatting out. You can do things replace, replace first or replace. So you can give it one string and say, hey, replace the word Ted with, Cindy and it'll replace it either in all cases or in just the first case. Remove is very similar to that. Truncate basically says, well, string might be really long but make sure you only show the first twenty six characters and then it'll ellipses for you after that. And so truncate works on characters. Truncate word works on words. So you can say, just show the first ten words and after that ellipses. Capitalize will capitalize the string and strip HTML to duplicate. Then new line to br. So a lot of times your string might have line breaks and we wanna replace those with br tags which are an HTML tag. So if you didn't do that in HTML, those those lines would actually all be one after another. So, to look at this, these text filters, I said, there's a lot more text filters. So let's let's take a look at where we would go to see those. And I have a slide that will show this a little bit later, but if you just got to rockrms.com/lava, this will list all of the filters within, lava. If I go to text filters, I would see all of these. Okay. So if for instance, I wanted to look at the truncate and I wasn't I wasn't really familiar how that worked, all I to do is just click on it and it'll show me some examples. So in this case, have the full name of Ted Decker truncate to nine characters and it's gonna give me nine characters. Now, the ellipses count as characters so that's why there's less than nine letters. So you need to to recognize that. Okay. So you can see all the optional parameters too. So we just saw before that they were you just provided the filter but you can have these filters kind of options. And so on truncate, that's where we pass in, we put a little colon, then we say nine characters and and that's actually fine if I just want ellipses but if I want to have something other than ellipses, I can put whatever I want there. Okay. So let's flip back. Okay. There's also numeric filters. So if my variable is not text, it's actually a number, I can do all kinds of things, with number filters. Mainly what I'm gonna be doing in here is math. So I can do plus, minus, times, divide. But you can do some others to quantity and to string. So let's take a look at those. Okay. So let's just say I'm given the data here, person and it has, an array, so which is basically array is a fancy way of saying multiple values, and each of those values is a is a phone number. Okay? So what I'm gonna do first is I'm gonna get the number of phone numbers. Okay? So this array is called phone numbers. If I if I pipe it through size, that's gonna give me the count of how many phone numbers are in that array. And I'm gonna store that count into this new variable called phone count. Okay. So now we get down to the template with the filter. So we're basically gonna say, Ted has how many phone numbers? And so what we do is we give it a string phone number and we're gonna pipe it through to quantity and pass it the number of of phone numbers that we have. In this case, three. And so what to quantity is gonna do is it's gonna pluralize this string if the quantity is more than one. And so that allows us to do this kind of logic down here where it actually says phone numbers. Remember, we we only said phone numbers. So it said, hey, there's there's more than one so I'm gonna pluralize phone number. Now, if you're doing this in regular code, if you're using a coding language, this would be quite a few lines of code to to do just that simple operator. But in Lava, it's one simple filter that you can that you can use. There's also date filters. So if you want to do some, , subtracting of dates, take take two days off this date or show me how many days are between two different dates, there's some great date filters in here too. And again, in all of these, there's actually a lot more if you go out to to the website. So let's look at an example of a date filter. Now, live filters as we saw, you pass in a variable. That's the starting point. And you can do the same thing with date. But it also has this very, simple and and powerful way of saying just give me the the date and time right now. So if I give it, the string now with single quotes and pipe that through the date filter, it's gonna allow me to format that date in lots of different ways. Okay? So in this case, we're just saying three d's means spell out Wednesday, spell out the day of the week, , fully. And then same thing with month. Four four big capital m's gives me the full month. And then one little d tells me just give me the date of the month. And because there's only one, it's gonna give me just that in in numeric format with no leading zero. And then four wise would be the year as four digits. Okay. Now, you are probably me and you you can't remember those those little codes. I've been working at those codes forever and I still don't remember them. So every time I do this and I'll admit to it, I come out here and I look at the date filter and then here's my cheat sheet. Okay? Some people keep these in their head, I choose not to. So it's just a lot easier just to come out here and look at them. And it's very very simple to remember if you do that. Okay. So let's look at another date filter called humanize date time because it's it's pretty cool. It allows you to do some really fancy stuff with no logic. So over here we have our data and one of the fields is anniversary date and that is a date. So we come over here we just say, hey, give me the the full name and then let's just put the text was married and let's take the anniversary date and let's pipe it through this filter called humanize date time. Okay. And so what humanize date time is is it takes the the date and it determines how long ago it was and it spells it out in in a format that humans us, we would appreciate that. So it basically says Ted Decker was married eighteen years ago. Now what's really powerful about this is it looks at that date and it'll actually return back different things. So if that was two days ago, it'd say two days ago. If it was two hours ago, it'd say two hours ago. And if it was two months and so on. So it's it's really powerful on how it it rolls this out. Again, if you're doing this in a programming language, this would be a lot of code that you'd be writing. But you get this all pretty much for free just by passing it and piping it through humanized date time. So whenever you're working with dates and you wanna show a duration, this is your go to right here. Okay. So let's look at at data again here, and look at another, construct which is attributes. Now, if you're wondering the difference between a property and an attribute, we have a whole video on that. We highly recommend you go out and watch that video so you understand fully the difference between a property of a entity and its attribute. I'm assuming you've already watched that and assuming you understand this this construct. So we're given the current person. Okay? And so we have full name and anniversary date. Now, I wanna know the employer of the person. Now, employer is not a property of the person model. Okay? It's an attribute of the person model model. So here, I'm just going to current person dot nickname. That's gonna give me the the current person. I can get their their nickname. But now I need the attribute of from that person. So basically, to do that, all I do is say current person, pipe it through the the filter called attribute, and then I give the attribute key. Okay. So whenever you set up an attribute, you make a key and that's what you use in Lava to do this. Okay. So I'm this basically saying current person, pipe, attribute, employer. Okay? And it's really important that whenever you wanna go get an attribute, you do it in this format. Okay? Always pipe it through attribute and use the key. In this case, I get Rocksolid Church because that's where TED works. Okay. So as we noted, there's different filter types. There's text, there's date, there's numeric. We've we've seen those. There's also some that work on arrays, work on people, and work on attributes. We saw that one also. Let's just take a quick second and flip over and look at some of the people ones. So people, if I have a current person or I have a person in in in a variable, I can do all kinds of things. I can I can get its address and there's lots of different formatting you can do for that? I can find out what campus they're a part of. I can get their a list of their children. I can get their family name. I can get groups that they're in. So I can say, hey, give me all the groups of this type that this person's in. Lots of of, really great and powerful filters, where if you have a person, you can get a ton more information about that person. Okay? So definitely come out here and learn everything that you can do on those filter types. And again, this is just a little reminder. This is where you go to get that information. Rockrms.com/lava. If you're doing any kind of lava, you should have this tab open almost all the time. So don't feel you will you'll get to the point where you just memorize all this and it. I'm always out here, using this page for reference. And so that's a quick look at using filters within Lava.