casid / jte

Secure and speedy templates for Java and Kotlin.
https://jte.gg
Apache License 2.0
737 stars 54 forks source link

Generic template #348

Closed guxingke closed 3 months ago

guxingke commented 3 months ago
@param columns: List<Column<Application>>  = emptyList()
<select name="__sort">
    <option>---</option>
    @for(obj in columns)
        @if(obj.comparator !=null)
            <option value="-${obj.name}"
                    selected="${rm.getOrDefault("__sort", "") == "-${obj.name}"}">
                -${obj.title}</option>
            <option value="${obj.name}"
                    selected="${rm.getOrDefault("__sort", "") == obj.name}">${obj.title}</option>
        @endif
    @endfor
</select>

if I want to extract code as template, Application as a generic parameter


this way it can be reused, It seems not possible yet.

casid commented 3 months ago

Welcome @guxingke! I'm sorry, templates with generic types are not supported at the moment.

casid commented 3 months ago

If the template is not interested about the generic types, I think wildcards should work.

In your example List<Column<?>>.

guxingke commented 3 months ago

If the template is not interested about the generic types, I think wildcards should work.

In your example List<Column<?>>.


thank you , yes , in the current scenario, this solution is sufficient.