|
| 1 | +### List of supported default Qute resolvers from the [Qute Reference Guide](https://quarkus.io/guides/qute-reference): |
| 2 | + |
| 3 | +Below is a list of default value resolvers supported in Qute templates: |
| 4 | + |
| 5 | +#### [Built-in Resolvers](https://quarkus.io/guides/qute-reference#built-in-resolvers) |
| 6 | +- `ifTruthy(base : T, arg : java.lang.Object) : T` - Outputs the default value if the base object cannot be resolved or the base Object otherwise. |
| 7 | +``` |
| 8 | +{item.isActive.ifTruthy(item.name)} |
| 9 | +``` |
| 10 | + |
| 11 | +- `orEmpty(base : java.lang.Iterable<T>) : java.util.List<T>` - Outputs an empty list if the previous part cannot be resolved or resolves to null. |
| 12 | +``` |
| 13 | +{#for pet in pets.orEmpty} |
| 14 | + {pet.name} |
| 15 | +{/for} |
| 16 | +``` |
| 17 | + |
| 18 | +- `orEmpty(base : T) : java.util.List<T>` - Outputs an empty list if the previous part cannot be resolved or resolves to null. |
| 19 | +``` |
| 20 | +{#for pet in pets.orEmpty} |
| 21 | + {pet.name} |
| 22 | +{/for} |
| 23 | +``` |
| 24 | + |
| 25 | +- `or(base : T, arg : java.lang.Object) : T` - Outputs the default value if the previous part cannot be resolved or resolves to null. |
| 26 | +``` |
| 27 | +{person.name ?: 'John'} |
| 28 | +{person.name or 'John'} |
| 29 | +{person.name.or('John')} |
| 30 | +``` |
| 31 | + |
| 32 | +#### [Arrays](https://quarkus.io/guides/qute-reference#arrays) |
| 33 | +- `length(base : T[]) : int` - The length of the array. |
| 34 | +``` |
| 35 | +{myArray.length} |
| 36 | +``` |
| 37 | + |
| 38 | +- `size(base : T[]) : int` - The size of the array. |
| 39 | +``` |
| 40 | +{myArray.size} |
| 41 | +``` |
| 42 | + |
| 43 | +- `get(base : T[], index : int) : T` - Returns the element at the specified `index` from the given array. |
| 44 | +``` |
| 45 | +{myArray.get(0)} |
| 46 | +``` |
| 47 | + |
| 48 | +- `take(base : T[], n : int) : T[]` - Returns the first `n` elements from the given array; throws an `IndexOutOfBoundsException` if `n` is out of range. |
| 49 | +``` |
| 50 | +{#for r in myArray.take(3)} |
| 51 | +``` |
| 52 | + |
| 53 | +- `takeLast(base : T[], n : int) : T[]` - Returns the last `n` elements from the given list; throws an `IndexOutOfBoundsException` if `n` is out of range. |
| 54 | +``` |
| 55 | +{#for r in myArray.takeLast(3)} |
| 56 | +``` |
| 57 | + |
| 58 | +- `@java.lang.Integer(base : T[]) : T` - Returns the element at the specified `index` from the given array. |
| 59 | +``` |
| 60 | +{myArray.0} |
| 61 | +``` |
| 62 | + |
| 63 | +#### [Character Escapes](https://quarkus.io/guides/qute-reference#character-escapes) |
| 64 | +- `raw(base : java.lang.Object) : io.quarkus.qute.RawString` - Marks the object so that character escape is not needed and can be rendered as is. |
| 65 | +``` |
| 66 | +{paragraph.raw} |
| 67 | +``` |
| 68 | + |
| 69 | +- `safe(base : java.lang.Object) : io.quarkus.qute.RawString` - Marks the object so that character escape is not needed and can be rendered as is. |
| 70 | +``` |
| 71 | +{paragraph.safe} |
| 72 | +``` |
| 73 | + |
| 74 | +#### [Virtual Methods](https://quarkus.io/guides/qute-reference#virtual_methods) |
| 75 | +- A virtual method is a part of an expression that looks like a regular Java method invocation. It’s called "virtual" because it does not have to match the actual method of a Java class. In fact, like normal properties a virtual method is also handled by a value resolver. The only difference is that for virtual methods a value resolver consumes parameters that are also expressions. |
| 76 | + |
| 77 | +Virtual method usage: |
| 78 | +``` |
| 79 | +{item.buildName(item.name,5)} |
| 80 | +``` |
| 81 | + |
| 82 | +Virtual method definition: |
| 83 | +```java |
| 84 | +class Item { |
| 85 | + String buildName(String name, int age) { |
| 86 | + return name + ":" + age; |
| 87 | + } |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +#### [Maps](https://quarkus.io/guides/qute-reference#maps) |
| 92 | +- `size(base : @java.util.Map<T, T>) : int` - The size of the map. |
| 93 | +``` |
| 94 | +{myMap.size} |
| 95 | +``` |
| 96 | + |
| 97 | +#### [Collections](https://quarkus.io/guides/qute-reference#collections) |
| 98 | +- `take(base : java.util.List<T>, n : int) : java.util.List<T>` - Returns the first n elements from the given list; throws an IndexOutOfBoundsException if n is out of range |
| 99 | +``` |
| 100 | +{#for r in recordsList.take(3)} |
| 101 | +``` |
| 102 | + |
| 103 | +- `@java.lang.Integer(base : java.util.List<T>) : T` - Returns the element at the specified `index` from the given list. |
| 104 | +``` |
| 105 | +{myList.0} |
| 106 | +``` |
| 107 | + |
| 108 | +#### [Numbers](https://quarkus.io/guides/qute-reference#numbers) |
| 109 | +- `mod` - Modulo operation |
| 110 | +``` |
| 111 | +{#if counter.mod(5) == 0} |
| 112 | +``` |
| 113 | + |
| 114 | +#### [Time](https://quarkus.io/guides/qute-reference#time) |
| 115 | +- `format(pattern)` - Formats temporal objects from the `java.time` package. |
| 116 | +``` |
| 117 | +{dateTime.format('d MMM uuuu')} |
| 118 | +``` |
| 119 | + |
| 120 | +- `format(pattern, locale)` - Formats temporal objects from the `java.time` package. |
| 121 | +``` |
| 122 | +{dateTime.format('d MMM uuuu',myLocale)} |
| 123 | +``` |
| 124 | + |
| 125 | +- `format(pattern, locale, timeZone)` - Formats temporal objects from the `java.time` package. |
| 126 | +``` |
| 127 | +{dateTime.format('d MMM uuuu',myLocale,myTimeZoneId)} |
| 128 | +``` |
0 commit comments