- All Implemented Interfaces:
- com.mitchellbosecke.pebble.extension.Extension
public class RouteExtension
extends com.mitchellbosecke.pebble.extension.AbstractExtension
Extension that creates an url for a route, from a nameOrUriPattern and parameters.
You can use it in pebble template like:
<a href="{{ route('quote', {'symbol': stock.symbol }) }}">{{ stock.symbol }}</a>
where quote is a route name defined like:
GET("/quote", routeContext -> {
ParameterValue symbol = routeContext.getParameter("symbol");
if (symbol.isEmpty()) {
routeContext.getResponse().badRequest().send("Specify a symbol as parameter");
} else {
Stock stock = dataStore.select(Stock.class).where(Stock.SYMBOL.eq(symbol.toString())).get().first();
List<Quote> quotes = dataStore.select(Quote.class).where(Quote.SYMBOL.eq(stock.symbol)).get().toList();
Map<String, Object> model = new HashMap<>();
model.put("stock", stock);
model.put("quotes", quotes);
routeContext.render("quote", model);
}
}).named("quote");
- Author:
- Decebal Suiu