Class Template


  • @ProviderType
    public final class Template
    extends java.lang.Object
    Template utility methods
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @Nullable TemplatePathInfo forPage​(@NotNull com.day.cq.wcm.api.Page page, @NotNull TemplatePathInfo @NotNull ... templates)
      Lookup template for given page.
      static <E extends java.lang.Enum<E> & TemplatePathInfo>
      @Nullable TemplatePathInfo
      forPage​(@NotNull com.day.cq.wcm.api.Page page, @NotNull java.lang.Class<E> @NotNull ... templateEnums)
      Lookup template for given page.
      static @Nullable TemplatePathInfo forTemplatePath​(@NotNull java.lang.String templatePath, @NotNull TemplatePathInfo @NotNull ... templates)
      Lookup a template by the given template path.
      static <E extends java.lang.Enum<E> & TemplatePathInfo>
      @Nullable TemplatePathInfo
      forTemplatePath​(@NotNull java.lang.String templatePath, @NotNull java.lang.Class<E> @NotNull ... templateEnums)
      Lookup a template by the given template path.
      static @Nullable java.lang.String getResourceTypeFromTemplatePath​(@NotNull java.lang.String templatePath)
      Gets the resource type for a given template path.
      static boolean is​(@NotNull com.day.cq.wcm.api.Page page, @NotNull TemplatePathInfo @NotNull ... templates)
      Checks if the given page uses a specific template.
      static boolean is​(@NotNull com.day.cq.wcm.api.Page page, @NotNull java.lang.String @NotNull ... templatePaths)
      Checks if the given page uses a specific template.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getResourceTypeFromTemplatePath

        @Nullable
        public static @Nullable java.lang.String getResourceTypeFromTemplatePath​(@NotNull
                                                                                 @NotNull java.lang.String templatePath)
        Gets the resource type for a given template path.

        This is based on the assumption that:

        • Given a template path is /apps/{app_path}/templates/{optional_path}/{template_path}
        • Then the resource path is at {app_path}/components/{optional_path}/page/{template_path}
        Parameters:
        templatePath - Template path
        Returns:
        Resource type path or null if template path did not match expectations
      • is

        public static boolean is​(@NotNull
                                 @NotNull com.day.cq.wcm.api.Page page,
                                 @NotNull
                                 @NotNull TemplatePathInfo @NotNull ... templates)
        Checks if the given page uses a specific template.
        Parameters:
        page - AEM page
        templates - Template(s)
        Returns:
        true if the page uses the template
      • is

        public static boolean is​(@NotNull
                                 @NotNull com.day.cq.wcm.api.Page page,
                                 @NotNull
                                 @NotNull java.lang.String @NotNull ... templatePaths)
        Checks if the given page uses a specific template.
        Parameters:
        page - AEM page
        templatePaths - Template path(s)
        Returns:
        true if the page uses the template
      • forTemplatePath

        @Nullable
        public static @Nullable TemplatePathInfo forTemplatePath​(@NotNull
                                                                 @NotNull java.lang.String templatePath,
                                                                 @NotNull
                                                                 @NotNull TemplatePathInfo @NotNull ... templates)
        Lookup a template by the given template path.
        Parameters:
        templatePath - Path of template
        templates - Templates
        Returns:
        The TemplatePathInfo instance or null for unknown template paths
      • forTemplatePath

        @SafeVarargs
        @Nullable
        public static <E extends java.lang.Enum<E> & TemplatePathInfo> @Nullable TemplatePathInfo forTemplatePath​(@NotNull
                                                                                                                  @NotNull java.lang.String templatePath,
                                                                                                                  @NotNull
                                                                                                                  @NotNull java.lang.Class<E> @NotNull ... templateEnums)
        Lookup a template by the given template path.
        Type Parameters:
        E - Template enum
        Parameters:
        templatePath - Path of template
        templateEnums - Templates
        Returns:
        The TemplatePathInfo instance or null for unknown template paths
      • forPage

        @Nullable
        public static @Nullable TemplatePathInfo forPage​(@NotNull
                                                         @NotNull com.day.cq.wcm.api.Page page,
                                                         @NotNull
                                                         @NotNull TemplatePathInfo @NotNull ... templates)
        Lookup template for given page.
        Parameters:
        page - Page
        templates - Templates
        Returns:
        The TemplatePathInfo instance or null for unknown template paths
      • forPage

        @SafeVarargs
        @Nullable
        public static <E extends java.lang.Enum<E> & TemplatePathInfo> @Nullable TemplatePathInfo forPage​(@NotNull
                                                                                                          @NotNull com.day.cq.wcm.api.Page page,
                                                                                                          @NotNull
                                                                                                          @NotNull java.lang.Class<E> @NotNull ... templateEnums)
        Lookup template for given page.
        Type Parameters:
        E - Template enum
        Parameters:
        page - Page
        templateEnums - Templates
        Returns:
        The TemplatePathInfo instance or null for unknown template paths