Search in sources :

Example 1 with TemplateRenderer

use of com.github.bordertech.wcomponents.template.TemplateRenderer in project wcomponents by BorderTech.

the class WTemplateRenderer method doRender.

/**
 * Paints the given WTemplate.
 *
 * @param component the WTemplate to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WTemplate template = (WTemplate) component;
    // Setup the context
    Map<String, Object> context = new HashMap<>();
    // Make the component available under the "wc" key.
    context.put("wc", template);
    // Load the parameters
    context.putAll(template.getParameters());
    // Get template renderer for the engine
    String engine = template.getEngineName();
    if (Util.empty(engine)) {
        engine = ConfigurationProperties.getDefaultRenderingEngine();
    }
    TemplateRenderer templateRenderer = TemplateRendererFactory.newInstance(engine);
    // Render
    if (!Util.empty(template.getTemplateName())) {
        // Render the template
        templateRenderer.renderTemplate(template.getTemplateName(), context, template.getTaggedComponents(), renderContext.getWriter(), template.getEngineOptions());
    } else if (!Util.empty(template.getInlineTemplate())) {
        // Render inline
        templateRenderer.renderInline(template.getInlineTemplate(), context, template.getTaggedComponents(), renderContext.getWriter(), template.getEngineOptions());
    }
}
Also used : HashMap(java.util.HashMap) TemplateRenderer(com.github.bordertech.wcomponents.template.TemplateRenderer) WTemplate(com.github.bordertech.wcomponents.WTemplate)

Aggregations

WTemplate (com.github.bordertech.wcomponents.WTemplate)1 TemplateRenderer (com.github.bordertech.wcomponents.template.TemplateRenderer)1 HashMap (java.util.HashMap)1