Class LanguageLinkHandlebarsHelper

  • All Implemented Interfaces:
    com.github.jknack.handlebars.Helper<Object>

    @Component
    public class LanguageLinkHandlebarsHelper
    extends BaseHelper
    The {{{languageLink ...}}} handlebars helper outputs a link to the current publish page in selected language.

    Usage

    It can be used as either a standard handlebars expression or a block level expression, with the latter providing the web developer with more control over the link.

    Attributes

    The expression itself is quite simple, taking only a single attribute.

    • target - The language used to build the linkn.

    Examples

    Standard expression

     <p>{{{languageLink target="language_code"}}}</p>
     

    In the above example a standard link is generated and returned with the URL to the page in the target language and using the language name for the link. It should be noted that as the handlebars expression is expected to return HTML, it should be triple-stashed.

    Block expression

      {{#languageLink target="language_code"}}
        <p><a href="{{targetLanguageURL}}" lang="{{targetLanguageCode}}" >{{targetLanguageName}}</a></p>
      {{else}}
        <p>The content is not translated into {{targetLanguageName}}</p>
      {{/languageLink}}
     

    As can be seen in the code snippet above, the standard link is modified by adding the name of the language to the link description, and the lang attribute within the generated link with the language code. If there is no page in the target language, then only the language name is available.

    When used as a block-level element, the {{targetLanguageURL}}, {{targetLanguageCode}} and {{targetLanguageName}} handlebars expressions are available for use, giving the web developer much more control over the generated HTML.

    • Constructor Detail

      • LanguageLinkHandlebarsHelper

        @Autowired
        public LanguageLinkHandlebarsHelper​(ILanguageAPI languageApi,
                                            IJsonAPI jsonApi)
    • Method Detail

      • apply

        public Object apply​(Object context,
                            com.github.jknack.handlebars.Options options)
                     throws IOException
        Description copied from class: BaseHelper
        The apply method is the main entry point for handlebars.java helpers.

        It is called internally by the handlebars.java engine when a matching handlebars.java expression is encountered.

        Specified by:
        apply in interface com.github.jknack.handlebars.Helper<Object>
        Specified by:
        apply in class BaseHelper
        Parameters:
        context - The currently executing context.
        options - The options.
        Returns:
        The generated output.
        Throws:
        IOException - If processing of the expressions fails.