Class Template


@Bean(typeName="template") public class Template extends HtmlElementMixed
DTO for an HTML <template> element.

The template element represents a template for a fragment of HTML that can be cloned and inserted into the document by script. It is used to define reusable HTML content that can be instantiated multiple times using JavaScript. The template element is not rendered in the document until its content is cloned and inserted into the DOM. It is commonly used for creating dynamic content, such as repeating elements in lists or generating content based on data.

Examples:

import static org.apache.juneau.bean.html5.HtmlBuilder.*; // Simple template Template simple = template( p("This is a template paragraph.") ); // Template with styling Template styled = template( div( h3("Item Title"), p("Item description") )._class("item") )._class("item-template"); // Template with complex content Template complex = template( article( header( h2("Article Title"), p("Article subtitle") ), p("Article content goes here."), footer("Article footer") ) ); // Template with ID Template withId = template() .id("user-card-template") .children( div()._class("user-card") .children( img().src("/avatar.jpg").alt("User Avatar"), h3().children("User Name"), p().children("User Bio") ) ); // Template with styling Template styled2 = template() .style("display: none;") .children( div()._class("modal") .children( h2().children("Modal Title"), p().children("Modal content") ) ); // Template with multiple elements Template multiple = template() .children( div()._class("product-card") .children( img().src("/product.jpg").alt("Product Image"), h3().children("Product Name"), p().children("Product Description"), span()._class("price").children("$99.99"), button().children("Add to Cart") ) ); // Template with form Template withForm = template() .children( form()._class("comment-form") .children( textarea().placeholder("Enter your comment"), button().type("submit").children("Submit Comment") ) );

The following convenience methods are provided for constructing instances of this bean:

See Also: