### Example of String Parameter Usage Source: https://github.com/jknack/handlebars.java/blob/master/README.md Illustrates the output when using the 'sayHi' helper with string parameters enabled. ```html {{sayHi this edgar}} ``` -------------------------------- ### Example of String Parameter Result Source: https://github.com/jknack/handlebars.java/blob/master/README.md Shows the resulting string after the 'sayHi' helper is applied with string parameters. ```text Hello edgar! ``` -------------------------------- ### Handlebars Template Example (home.hbs) Source: https://github.com/jknack/handlebars.java/blob/master/README.md A simple Handlebars template demonstrating iteration over a list of items. ```handlebars ``` -------------------------------- ### Null Cache Implementation Example Source: https://github.com/jknack/handlebars.java/blob/master/README.md A basic implementation of a template cache that bypasses caching and directly parses the source. ```java Template get(TemplateSource source, Parser parser) throws IOException { return parser.parse(source); } ``` -------------------------------- ### Handlebars Template Syntax Error Example Source: https://github.com/jknack/handlebars.java/blob/master/README.md Example of a syntax error in a Handlebars template where an expected token was not found. ```handlebars {{value ``` -------------------------------- ### JSON Data for Template Source: https://github.com/jknack/handlebars.java/blob/master/README.md Example JSON data structure to be merged with the home.hbs template. ```json { "items": [ { "name": "Handlebars.java rocks!" } ] } ``` -------------------------------- ### Precompile Helper Example Source: https://github.com/jknack/handlebars.java/blob/master/README.md The 'precompile' helper generates JavaScript code from a Handlebars template. It requires the template name as a context. ```html ``` -------------------------------- ### Register a List Helper using the Helper Interface Source: https://github.com/jknack/handlebars.java/blob/master/README.md Register a helper for processing lists. This example iterates over a list and applies the block helper to each item. ```java handlebars.registerHelper("blog-list", new Helper>() { public CharSequence apply(List list, Options options) { String ret = ""); } }); ``` -------------------------------- ### Handlebars.js Scope Resolution Example Source: https://github.com/jknack/handlebars.java/blob/master/README.md Demonstrates the default scope resolution behavior in Handlebars.js, which does not look up the context stack for missing attributes. ```html Hello {{#child}}{{value}}{{/child}} ``` -------------------------------- ### Handlebars.java Scope Resolution Example Source: https://github.com/jknack/handlebars.java/blob/master/README.md Illustrates how Handlebars.java resolves scope differently from Handlebars.js by looking up missing attributes in the context stack. Use 'this.' to explicitly refer to the current scope. ```json { "value": "parent", "child": { } } ``` ```html Hello {{#child}}{{value}}{{/child}} ``` ```html Hello {{#child}}{{this.value}}{{/child}} ``` -------------------------------- ### Generated i18nJs JavaScript Code Source: https://github.com/jknack/handlebars.java/blob/master/README.md This is an example of the JavaScript code generated by the 'i18nJs' helper, setting up translations for the I18n.js library. ```javascript ``` -------------------------------- ### Use Jackson 1.x JSON Helper in Template Source: https://github.com/jknack/handlebars.java/blob/master/README.md Example of using the registered Jackson 1.x JSON helper within a Handlebars template to render a context object as JSON. ```handlebars {{json context [view="foo.MyFullyQualifiedClassName"] [escapeHTML=false] [pretty=false]}} ``` -------------------------------- ### Use Jackson 1.x JSON Helper with View Alias in Template Source: https://github.com/jknack/handlebars.java/blob/master/README.md Example of using the Jackson 1.x JSON helper with a defined view alias in a Handlebars template. ```handlebars {{json context [view="myView"] [escapeHTML=false] [pretty=false]}} ``` -------------------------------- ### Embedded Helper Example Source: https://github.com/jknack/handlebars.java/blob/master/README.md The 'embedded' helper allows embedding a Handlebars template directly within an HTML script tag. ```html ... {{embedded "user"}} ... ``` -------------------------------- ### Handlebars Partial Not Found Error Source: https://github.com/jknack/handlebars.java/blob/master/README.md Example of an error message when a Handlebars partial is not found, including the call stack. ```plaintext /deep1.hbs:1:5: The partial '/deep2.hbs' could not be found {{> deep2 ^ at /deep1.hbs:1:10 at /deep.hbs:1:10 ``` -------------------------------- ### Initialize Handlebars with a Custom TemplateLoader Source: https://github.com/jknack/handlebars.java/blob/master/README.md Demonstrates how to create a Handlebars instance with a custom TemplateLoader implementation. ```java TemplateLoader loader = ...; Handlebars handlebars = new Handlebars(loader); ``` -------------------------------- ### Running the Handlebars.java Server Source: https://github.com/jknack/handlebars.java/blob/master/README.md Execute the server JAR from the command line, specifying the directory containing your templates. ```bash java -jar handlebars-proto-${current-version}.jar -dir myTemplates ``` -------------------------------- ### Precompile Helper Usage with Wrapper Option Source: https://github.com/jknack/handlebars.java/blob/master/README.md Illustrates the usage of the 'precompile' helper with an optional 'wrapper' argument to control the output format. ```handlebars {{precompile "template" [wrapper="anonymous, amd or none"]}} ``` -------------------------------- ### Accessing Template with Multiple Data Sources Source: https://github.com/jknack/handlebars.java/blob/master/README.md Use the 'data' parameter in the URI to test multiple datasets with a single template. The file extension is not required. ```bash http://localhost:6780/home.hbs?data=mytestdata ``` -------------------------------- ### Run Precompile Goal via Maven Command Source: https://github.com/jknack/handlebars.java/blob/master/handlebars-maven-plugin/README.md Execute the precompile goal directly using the Maven command line. ```bash mvn handlebars:precompile ``` -------------------------------- ### Accessing the Rendered Template Source: https://github.com/jknack/handlebars.java/blob/master/README.md Open a web browser and navigate to this URL to view the rendered template. ```bash http://localhost:6780/home.hbs ``` -------------------------------- ### Register JavaScript Helpers from a File Source: https://github.com/jknack/handlebars.java/blob/master/README.md Load and register JavaScript helpers defined in a specified file. Ensure the file path is correct. ```java handlebars.registerHelpers(new File("helpers.js")); ``` -------------------------------- ### Run i18njs Goal via Maven Command Source: https://github.com/jknack/handlebars.java/blob/master/handlebars-maven-plugin/README.md Execute the i18njs goal directly using the Maven command line. ```bash mvn handlebars:i18njs ``` -------------------------------- ### Configuring Handlebars.js Version for Precompilation Source: https://github.com/jknack/handlebars.java/blob/master/README.md Shows how to specify a different version of handlebars.js for the precompilation process in Handlebars.java. ```java Handlebars handlebars = new Handlebars(); handlebars.handlebarsJsFile("/handlebars-v2.0.0.js"); ``` -------------------------------- ### Initialize Jasmine Environment Source: https://github.com/jknack/handlebars.java/blob/master/handlebars-maven-plugin/src/test/resources/jasmine/SpecRunner.html Sets up the Jasmine testing environment, configures the HTML reporter, and defines a spec filter. This code should be included in your SpecRunner.html file to initialize Jasmine. ```javascript (function() { var jasmineEnv = jasmine.getEnv(); jasmineEnv.updateInterval = 1000; var htmlReporter = new jasmine.HtmlReporter(); jasmineEnv.addReporter(htmlReporter); jasmineEnv.specFilter = function(spec) { return htmlReporter.specFilter(spec); }; var currentWindowOnload = window.onload; window.onload = function() { if (currentWindowOnload) { currentWindowOnload(); } execJasmine(); }; function execJasmine() { jasmineEnv.execute(); } })(); ``` -------------------------------- ### Compile and Apply Template from Classpath Source: https://github.com/jknack/handlebars.java/blob/master/README.md This Java snippet shows how to compile a template named 'mytemplate' located in the classpath and apply it with a given string. ```java var handlebars = new Handlebars(); var template = handlebars.compile("mytemplate"); System.out.println(template.apply("Handlebars.java")); ``` -------------------------------- ### Access Helper Hash Parameters Source: https://github.com/jknack/handlebars.java/blob/master/README.md Access hash parameters (key-value pairs) passed to a helper using the options.hash() method. This is useful for passing configuration options. ```java handlebars.registerHelper("blog-list", new Helper() { public CharSequence apply(List list, Options options) { String classParam = options.hash("class"); assertEquals("blog-css", classParam); ... } }); handlebars.compileInline("{{#blog-list blogs class=\"blog-css\"}}{{/blog-list}}"); ``` -------------------------------- ### Using Multiple Value Resolvers Source: https://github.com/jknack/handlebars.java/blob/master/README.md Java code demonstrating how to configure Handlebars.java to use multiple value resolvers in a specific order. ```java Context context = Context .newBuilder(model) .resolver( MapValueResolver.INSTANCE, JavaBeanValueResolver.INSTANCE, FieldValueResolver.INSTANCE ).build(); ``` -------------------------------- ### Create and Apply a TypeSafeTemplate Source: https://github.com/jknack/handlebars.java/blob/master/README.md Compile a template inline and cast it to the defined TypeSafeTemplate interface. Set values using setter methods and apply the template. ```java UserTemplate userTmpl = handlebars.compileInline("{{name}} is {{age}} years old!") .as(UserTemplate.class); userTmpl.setAge(32); assertEquals("Edgar is 32 years old!", userTmpl.apply(new User("Edgar"))); ``` -------------------------------- ### Configuring a Custom Template Cache Source: https://github.com/jknack/handlebars.java/blob/master/README.md Demonstrates how to configure Handlebars.java to use a custom template cache implementation. ```java Handlebars hbs = new Handlebars() .with(new MyCache()); ``` -------------------------------- ### Accessing Precompiled Template Source: https://github.com/jknack/handlebars.java/blob/master/README.md Demonstrates how to access a precompiled Handlebars template in JavaScript. ```js var template = Handlebars.templates['user'] ``` -------------------------------- ### Configure TemplateLoader with Prefix and Suffix Source: https://github.com/jknack/handlebars.java/blob/master/README.md This Java snippet illustrates configuring a ClassPathTemplateLoader with a custom prefix and suffix to resolve template paths. ```java TemplateLoader loader = new ClassPathTemplateLoader(); loader.setPrefix("/templates"); loader.setSuffix(".html"); Handlebars handlebars = new Handlebars(loader); Template template = handlebars.compile("mytemplate"); System.out.println(template.apply("Handlebars.java")); ``` -------------------------------- ### i18n Helper with Different Bundle Source: https://github.com/jknack/handlebars.java/blob/master/README.md Shows how to use the 'i18n' helper with a custom ResourceBundle name, requiring a properties file with that name. ```html {{i18n "hello" bundle="myMessages"}} ``` -------------------------------- ### Access Helper Default Hash Parameters Source: https://github.com/jknack/handlebars.java/blob/master/README.md Access hash parameters, providing default values if the hash key is not supplied. This simplifies template usage by providing sensible defaults. ```java handlebars.registerHelper("blog-list", new Helper() { public CharSequence apply(List list, Options options) { String class = options.hash("class", "blog-css"); assertEquals("blog-css", class); ... } }); handlebars.compileInline("{{#blog-list blogs}}{{/blog-list}}"); ``` -------------------------------- ### Access Helper Parameters Source: https://github.com/jknack/handlebars.java/blob/master/README.md Access parameters passed to a helper using the options.param() method. Parameters are zero-indexed. ```java handlebars.registerHelper("blog-list", new Helper() { public CharSequence apply(List list, Options options) { String p0 = options.param(0); assertEquals("param0", p0); Integer p1 = options.param(1); assertEquals(123, p1); ... } }); Bean bean = new Bean(); bean.setParam1(123); Template template = handlebars.compileInline("{{#blog-list blogs \"param0\" param1}}{{/blog-list}}"); template.apply(bean); ``` -------------------------------- ### Register a Helper using the Helper Interface Source: https://github.com/jknack/handlebars.java/blob/master/README.md Register a custom helper by implementing the Helper interface. The apply method defines the helper's logic. ```java handlebars.registerHelper("blog", new Helper() { public CharSequence apply(Blog blog, Options options) { return options.fn(blog); } }); ``` -------------------------------- ### YAML Data for Template Source: https://github.com/jknack/handlebars.java/blob/master/README.md Alternative YAML data structure for the home.hbs template. ```yaml items: - name: Handlebars.java rocks! ``` -------------------------------- ### Extending Context Stack with Custom Data Source: https://github.com/jknack/handlebars.java/blob/master/README.md Java code demonstrating how to extend the Handlebars context stack with custom data like user information and other maps. ```java hookContextStack(Object model, Template template) { User user = ....;// Get the logged-in user from somewhere Map moreData = ...; Context context = Context .newBuilder(model) .combine("user", user) .combine(moreData) .build(); template.apply(context); context.destroy(); } ``` -------------------------------- ### Convert Resource Bundles to JavaScript with Maven Source: https://github.com/jknack/handlebars.java/blob/master/handlebars-maven-plugin/README.md Configure the plugin to convert Java Resource Bundles to JavaScript files for i18n.js. Specify the output directory, bundle name, and options for merging and AMD module generation. ```xml com.github.jknack handlebars-maven-plugin ${handlebars-version} i18njs prepare-package i18njs ${project.build.directory}/${project.build.finalName}/js messages false false UTF-8 ``` -------------------------------- ### i18n Helper with Message Formatting Source: https://github.com/jknack/handlebars.java/blob/master/README.md Illustrates using the 'i18n' helper with arguments to interpolate values into message patterns defined in the ResourceBundle. ```html {{i18n "hello" "Handlebars.java"}} ``` -------------------------------- ### Iterate and Display Stock Data with Handlebars Source: https://github.com/jknack/handlebars.java/blob/master/handlebars/src/test/resources/com/github/jknack/handlebars/bench/stocks.hbs.html Use the #each helper to loop through stock items and display symbol, name, price, change, and ratio. Access item properties directly or using the @index. ```handlebars {{#each items base=1}} {{/each}} # symbol name price change ratio {{&@index}} [{{&symbol}}](/stocks/{{&symbol}}) [{{&name}}]({{&url}}) **{{&price}}** {{&change}} {{&ratio}} ``` -------------------------------- ### i18n Helper with Specific Locale Source: https://github.com/jknack/handlebars.java/blob/master/README.md Demonstrates using the 'i18n' helper to fetch translations for a specific locale, requiring a locale-specific properties file. ```html {{i18n "hello" locale="es_AR"}} ``` -------------------------------- ### Precompile Handlebars Templates with Maven Source: https://github.com/jknack/handlebars.java/blob/master/handlebars-maven-plugin/README.md Configure the plugin in your pom.xml to precompile Handlebars/Mustache templates to JavaScript. Specify output file, template prefix, suffix, and handlebars.js file location. Optional settings include minimization, runtime, AMD module generation, encoding, and specific templates to process. ```xml com.github.jknack handlebars-maven-plugin ${handlebars-version} precompile prepare-package precompile ${project.build.directory}/${project.build.finalName}/js/helpers.js ${basedir}/src/main/webapp .hbs /handlebars-v1.3.0.js false false UTF-8 ``` -------------------------------- ### Compile and Apply Inline Template Source: https://github.com/jknack/handlebars.java/blob/master/README.md Demonstrates how to compile an inline Handlebars template and apply it with a given string value. This is useful for simple, dynamic string generation. ```java Handlebars handlebars = new Handlebars(); Template template = handlebars.compileInline("Hello {{this}}!"); System.out.println(template.apply("Handlebars.java")); ``` -------------------------------- ### Define Helper Methods in a HelperSource Class Source: https://github.com/jknack/handlebars.java/blob/master/README.md Define public methods in a class to be used as helpers. Method names become helper names. Context, parameters, and options are optional arguments. ```java public class HelperSource { public String blog(Blog blog, Options options) { return options.fn(blog); } public static String now() { return new Date().toString(); } public String render(Blog context, String param0, int param1, boolean param2, Options options) { return ... } } ``` -------------------------------- ### Precompiled Template Output Source: https://github.com/jknack/handlebars.java/blob/master/README.md This is the JavaScript output generated by the 'precompile' helper for the 'user' template. ```html ``` -------------------------------- ### Register Helpers from a HelperSource Class Source: https://github.com/jknack/handlebars.java/blob/master/README.md Register all public static methods from a HelperSource class as helpers. This is useful for utility-like helpers. ```java handlebars.registerHelpers(HelperSource.class); ``` -------------------------------- ### Registering String Helpers Source: https://github.com/jknack/handlebars.java/blob/master/README.md Note that string helpers are not registered by default and must be explicitly added to the Handlebars instance. ```markdown > NOTE: You need to register string helpers (they are not added by default) ``` -------------------------------- ### Access Helper Default Parameters Source: https://github.com/jknack/handlebars.java/blob/master/README.md Access parameters passed to a helper, providing default values if the parameter is not supplied. The default value is returned if the parameter index is out of bounds. ```java handlebars.registerHelper("blog-list", new Helper() { public CharSequence apply(List list, Options options) { String p0 = options.param(0, "param0"); assertEquals("param0", p0); Integer p1 = options.param(1, 123); assertEquals(123, p1); ... } }); Template template = handlebars.compileInline("{{#blog-list blogs}}{{/blog-list}}"); ``` -------------------------------- ### Register Helpers from a HelperSource Instance Source: https://github.com/jknack/handlebars.java/blob/master/README.md Register all public methods from a HelperSource instance as helpers. This allows for a more object-oriented approach to helper definition. ```java handlebars.registerHelpers(new HelperSource()); ``` -------------------------------- ### Include Helper for Partials Source: https://github.com/jknack/handlebars.java/blob/master/handlebars-helpers/README.md The include helper is a port from handlebars.js and supports plain partials, aligning with the Mustache Specification. It is necessary if you intend to use handlebars.js features that are not natively supported by Handlebars.java's partials. -------------------------------- ### Handlebars Template with Block Helper Source: https://github.com/jknack/handlebars.java/blob/master/README.md A simple Handlebars template using a block helper. ```handlebars {{#block}} {{/block}} ``` -------------------------------- ### Register a JavaScript Helper Source: https://github.com/jknack/handlebars.java/blob/master/README.md Register helpers written in JavaScript. This requires a JavaScript file containing Handlebars helper definitions. ```javascript Handlebars.registerHelper('hello', function (context) { return 'Hello ' + context; }) ``` -------------------------------- ### Enabling String Parameter Access in Helpers Source: https://github.com/jknack/handlebars.java/blob/master/README.md Configures Handlebars.java to resolve parameters by name when their values are not present in the context stack, allowing access via options.param(index). ```java Handlebars handlebars = new Handlebars() .stringParams(true); handlebars.registerHelper("sayHi", new Helper() { public Object apply(Object context, Options options) { return "Hello " + options.param(0) + "!"; } }); ``` -------------------------------- ### Embedded Helper Usage Source: https://github.com/jknack/handlebars.java/blob/master/README.md Shows the basic usage of the 'embedded' helper to include a template by its name. ```handlebars {{embedded "template"}} ``` -------------------------------- ### Configuring JavaBeanValueResolver Source: https://github.com/jknack/handlebars.java/blob/master/README.md Java code to configure Handlebars.java to use the JavaBeanValueResolver for accessing properties via getter methods. ```java Context context = Context .newBuilder(model) .resolver(JavaBeanValueResolver.INSTANCE) .build(); ``` -------------------------------- ### Configuring MethodValueResolver Source: https://github.com/jknack/handlebars.java/blob/master/README.md Java code to configure Handlebars.java to use the MethodValueResolver for accessing values via public methods. ```java Context context = Context .newBuilder(model) .resolver(MethodValueResolver.INSTANCE) .build(); ``` -------------------------------- ### Handlebars Syntax Error Reporting Format Source: https://github.com/jknack/handlebars.java/blob/master/README.md Illustrates the format of syntax error messages, including file, line, column, message, evidence, and stack trace. ```plaintext file:line:column: message evidence ^ [at file:line:column] ``` -------------------------------- ### Configuring MapValueResolver Source: https://github.com/jknack/handlebars.java/blob/master/README.md Java code to configure Handlebars.java to use the MapValueResolver for accessing values from Map objects. ```java Context context = Context .newBuilder(model) .resolver(MapValueResolver.INSTANCE) .build(); ``` -------------------------------- ### Number Helpers: isEven, isOdd, stripes Source: https://github.com/jknack/handlebars.java/blob/master/handlebars-helpers/README.md These helpers provide common number-related checks. Use `isEven` to determine if a number is even, and it can optionally return a custom string if true. The `stripes` helper is implied for alternating row styling. ```handlebars {{isEven number}} // output: even ``` ```handlebars {{isEven number "row-even"}} // output: row-even ``` -------------------------------- ### Registering a Helper Missing Implementation Source: https://github.com/jknack/handlebars.java/blob/master/README.md Overrides the default behavior of throwing an exception when a helper is not found by registering a 'helperMissing' implementation. ```java handlebars.registerHelperMissing(new Helper() { @Override public CharSequence apply(final Object context, final Options options) throws IOException { return options.fn.text(); } }); ``` -------------------------------- ### i18n Helper Basic Usage Source: https://github.com/jknack/handlebars.java/blob/master/README.md The 'i18n' helper retrieves translated strings from a Java ResourceBundle. It requires a 'messages.properties' file in the classpath. ```html {{i18n "hello"}} ``` -------------------------------- ### Register Jackson 1.x JSON Helper Source: https://github.com/jknack/handlebars.java/blob/master/README.md Register the Jackson 1.x JSON helper for use with Handlebars. This is useful for serializing objects to JSON within templates. ```xml com.github.jknack handlebars-json ${handlebars-version} ``` ```java handlebars.registerHelper("json", JacksonHelper.INSTANCE); ``` -------------------------------- ### Add Handlebars.java Maven Dependency Source: https://github.com/jknack/handlebars.java/blob/master/README.md Include this XML snippet in your pom.xml to add the Handlebars.java library as a project dependency. ```xml com.github.jknack handlebars ${handlebars-version} ``` -------------------------------- ### Register Jackson 1.x JSON Helper with View Alias Source: https://github.com/jknack/handlebars.java/blob/master/README.md Register the Jackson 1.x JSON helper with a custom view alias for more specific JSON serialization control. ```java handlebars.registerHelper("json", new JacksonHelper().viewAlias("myView", foo.MyFullyQualifiedClassName.class)); ``` -------------------------------- ### Add Jackson Module Dependency Source: https://github.com/jknack/handlebars.java/blob/master/README.md Include the Jackson module dependency for Handlebars.java. This enables JSON processing capabilities. ```xml com.github.jknack handlebars-jackson ${handlebars-version} ``` -------------------------------- ### Maven Dependency for Handlebars.java Source: https://github.com/jknack/handlebars.java/blob/master/README.md Add this dependency to your Maven project to include the handlebars-proto library. ```xml com.github.jknack handlebars-proto ${current-version} ``` -------------------------------- ### Configuring FieldValueResolver Source: https://github.com/jknack/handlebars.java/blob/master/README.md Java code to configure Handlebars.java to use the FieldValueResolver for accessing non-static fields directly. ```java Context context = Context .newBuilder(model) .resolver(FieldValueResolver.INSTANCE) .build(); ``` -------------------------------- ### Define a TypeSafeTemplate Interface Source: https://github.com/jknack/handlebars.java/blob/master/README.md Extend TypeSafeTemplate to create type-safe templates. Add setter methods for template variables. ```java public static interface UserTemplate extends TypeSafeTemplate { public UserTemplate setAge(int age); public UserTemplate setRole(String role); } ``` -------------------------------- ### Configuring JsonNodeValueResolver Source: https://github.com/jknack/handlebars.java/blob/master/README.md Java code to configure Handlebars.java to use the JsonNodeValueResolver for accessing values from JsonNode objects (Jackson 1.x/2.x). ```java Context context = Context .newBuilder(model) .resolver(JsonNodeValueResolver.INSTANCE) .build(); ``` -------------------------------- ### i18nJs Helper Usage Source: https://github.com/jknack/handlebars.java/blob/master/README.md The 'i18nJs' helper translates Java ResourceBundles into JavaScript code compatible with the I18n.js library. It can optionally specify a locale and bundle. ```handlebars {{i18nJs [locale] [bundle=messages]}} ``` -------------------------------- ### Configure HandlebarsViewResolver Value Resolvers Source: https://github.com/jknack/handlebars.java/blob/master/README.md Configure the HandlebarsViewResolver by setting its value resolvers. This allows customization of how values are resolved in templates. ```java HandlebarsViewResolver viewResolver = ...; viewResolver.setValueResolvers(...); ``` -------------------------------- ### Partial Helper Usage Source: https://github.com/jknack/handlebars.java/blob/master/README.md The 'partial' helper defines a named region that can be included elsewhere, working with 'block' for template inheritance. ```handlebars {{#partial "title"}} ... {{/partial}} ``` -------------------------------- ### Block Helper Usage Source: https://github.com/jknack/handlebars.java/blob/master/README.md The 'block' helper defines a named region within a template. It is used in conjunction with 'partial' for template inheritance. ```handlebars {{#block "title"}} ... {{/block}} ``` -------------------------------- ### Embedded Template Output Source: https://github.com/jknack/handlebars.java/blob/master/README.md This is the HTML output generated by the 'embedded' helper, including the template within a script tag. ```html ``` -------------------------------- ### TemplateCache Interface Definition Source: https://github.com/jknack/handlebars.java/blob/master/README.md Defines the contract for template caching mechanisms in Handlebars.java, including methods for clearing, evicting, and retrieving templates. ```java public interface TemplateCache { /** * Remove all mappings from the cache. */ void clear(); /** * Evict the mapping for this source from this cache if it is present. * * @param source the source whose mapping is to be removed from the cache */ void evict(TemplateSource source); /** * Return the value to which this cache maps the specified key. * * @param source source whose associated template is to be returned. * @param parser The Handlebars parser. * @return A template. * @throws IOException If input can't be parsed. */ Template get(TemplateSource source, Parser parser) throws IOException; } ``` -------------------------------- ### Use Message Helper in Template Source: https://github.com/jknack/handlebars.java/blob/master/README.md Utilize the 'message' helper within a Handlebars template to display localized messages using Spring's MessageSource. ```handlebars {{message "code" [arg]* [default="default message"]}} ``` -------------------------------- ### Assign Helper for Temporary Variables Source: https://github.com/jknack/handlebars.java/blob/master/handlebars-helpers/README.md Use the assign helper to create auxiliary or temporary variables within your Handlebars templates. This is useful for storing intermediate values that can be referenced later. ```handlebars {{#assign "benefitsTitle"}} benefits.{{type}}.title {{/assign}} {{i18n benefitsTitle}} ``` -------------------------------- ### Add SpringMVC Module Dependency Source: https://github.com/jknack/handlebars.java/blob/master/README.md Include the SpringMVC module dependency for Handlebars.java. This integrates Handlebars with Spring MVC applications. ```xml com.github.jknack handlebars-springmvc ${handlebars-version} ``` -------------------------------- ### Handlebars Block Helper Runtime Error Source: https://github.com/jknack/handlebars.java/blob/master/README.md Java code for a block helper that throws an IllegalArgumentException for invalid context types. ```java public CharSequence apply(final Object context, final Options options) throws IOException { if (context == null) { throw new IllegalArgumentException( "found 'null', expected 'string'"); } if (!(context instanceof String)) { throw new IllegalArgumentException( "found '" + context + "', expected 'string'"); } ... } ``` -------------------------------- ### MissingValueResolver Implementation (Deprecated) Source: https://github.com/jknack/handlebars.java/blob/master/README.md Provides a default value for template variables that resolve to null. This is deprecated for versions greater than 1.3.0. ```java MissingValueResolver missingValueResolver = new MissingValueResolver() { public String resolve(Object context, String name) { //return a default value or throw an exception ...; } }; Handlebars handlebars = new Handlebars().with(missingValueResolver); ``` -------------------------------- ### Handlebars Template Syntax Error Message Source: https://github.com/jknack/handlebars.java/blob/master/README.md The error message generated for the malformed Handlebars template. ```plaintext /templates.hbs:1:8: found 'eof', expected: 'id', 'parameter', 'hash' or '}' {{value ^ ``` -------------------------------- ### Handlebars Runtime Error Message Source: https://github.com/jknack/handlebars.java/blob/master/README.md The error message reported by Handlebars.java for a runtime error within a block helper. ```plaintext /base.hbs:2:4: found 'null', expected 'string' {{#block}} ... {{/block}} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.