Rock U - Lava - Filters
Transcribed Video Content
Lava can output all kinds of data, but often data doesn't come out looking exactly how you want it to look. Now Lava has a very large list of filters you can use to take raw data and turn it into something more helpful. You can use it for things such as pluralizing words, formatting dates, or even encrypting strings. There's a ton of different ways you can use filters. Let's go through a few examples and show you how easy the syntax is.
Let's look at it in Rock right now. Filters are super powerful and I'm looking at the filters section of the Lava documentation, which is on our community site. And I suggest you do the same because there's so many filters that you probably won't get the opportunity to remember all of them. There's just tons of them. There's tons of different capabilities, and then there's different things you can do to extend each filter.
And it's easy to find out what all those filters are and how you can extend them through our documentation. But let's look at an example of some text filters. So we're gonna go look at the upcase filter and you'll notice we just have an example here with some data passed in. We have the full name property and it says Ted Decker. Now what we're doing is we're just gonna use some simple HTML and we're using the merge field that takes a person's full name and outputs it, then this is where the filter comes in.
So we have this character here that we call a pipe, and you're gonna put that after your merge field, then you'll type the name of the filter and that's all it takes. And the output is gonna look a little bit different than the input. Here you can see Ted Decker is capitalized completely. And let's look at some other good examples. So here are some actual filters that I used on my version of Rock.
We're gonna look at some text filters first, and there's so many different categories as you saw before. I'm just gonna mention some different filters that are important and cover what a couple of them do. For example, with text filters, can do upcase, downcase, title case. You can pluralize or singularize really easily. You can pick the size, which is just the number of characters that come out.
You can take away HTML and more. But here's some data. We have Alicia Marble, her nickname and last name, and we're just doing a simple output here. You can see it says, hello, Alicia. Doesn't look any different than how you'd expect.
But now let's use our our first filter. You can see we have the same data, but by simply using that pipe in the upcase filter, it says Alicia in all caps. Now here is a more powerful example of how you can do many different things with filters. We've assigned this thing called work term, and it's simply a string of text that says request and let's filter it. So we're saying there are many, then we're putting in that work term which is request and we filter it once and we're pluralizing it.
So it'll say requests instead of request, then we can go even further and we can down case it, meaning we just take off that capital that's right here And then we stacked multiple filters and we turned what was request into requests and it's down case. Then here's just an idea of how powerful the pluralized filter is. We have the word man, just the text input here. And rather than it going from man to mans, it says men. Then same thing here, we have some powerful pluralization.
We have the word goose and we pluralize it and it says geese. Now let's move on to date filters. You'll use dates for all kinds of things in Rock and you may have your own preference or standard for how to output a date or you maybe want to add some time to a date, show the difference between two different dates and more. So the basic date filter will take a date. And by the way, this now word you see here with just some quotes around it, That's how in Rock you can pull the live time.
And we've just picked what we wanna take from that time. We're gonna output the actual name of the day, the month, and then the, day... Or sorry. Yeah. This was the actual name of the day.
This is the number of the day, and here is the year. So it says today is Tuesday, 07/07/2026, and there's all sorts of documentation on how you can get really specific dates output. Then this is a really helpful filter and it's called humanize date time. So we take an actual date we have in the system. This is a field on a person called anniversary date, and we're outputting it by saying person dot full name, which is Alicia Marble, and we're saying was married, and it says twenty years ago and that's because we took the anniversary date and use this filter which will make any date look prettier and just easier to understand than it was before.
Now some numeric filters, there's quite a few different ways you can change numbers including doing some things plus minus times divide, you can do math and much more. But we're taking this data which is a person's nickname and their phone numbers, and we're actually doing two different filters. One of these filters, this size filter is for text and two quantity is for... It's a numeric filter. But we're assigning phone count to a person's phone numbers and the size of their phone numbers.
So maybe you'd expect that what we get from this is a number and that's true, we're getting the phone count of a person. And in this case, that's three, then we're taking that output, we're actually gonna filter it again. So in this statement, we're saying Alicia has phone number and that's just the way we're identifying the phone number and we're using two quantity phone counts. So what that means is this text right here that we've output based on the number or the size of the number the number of phone numbers that come out, we will choose whether this is pluralized. So because there's three, phone numbers is pluralized, but if we just got one, if Alicia only had one phone number, it would say Alicia has one phone number.
So that's really helpful. Then attributes. So if you don't know about attributes, they're different than properties in Rock. I suggest you watch our video on attributes or read our documentation as knowing the difference is important. But we have an custom attribute called employer here.
And it's got a value of Rock solid church because that's the employer that Alicia has. And we're taking the current person's nickname, we're saying works at current person, then this filter is super powerful because with this, you can get the value of an attribute really easily. You just take this, which is an entity, and you type attribute, then you take the string, which is the name of that attribute and that's employer and it's actually gonna output the value of that attribute. Alright. Now filters are a really powerful part of your Lava Toolkit.
Thanks for watching this video and have a great day.