Monday, April 4, 2022

What is an HTML template tag? | How to use HTML template tag in AEM(Adobe Experience Manager)

 In this post, let us explore what an HTML template tag is and how to use an HTML template tag within AEM components.

The <template> tag stores HTML code fragments, which can be cloned and inserted into an HTML document.

The tag's content is hidden from users being stored on the client-side. It is inert until activated using JavaScript — the content inside the template tag is not loaded, e.g., Script doesn't run, images don't load, and audio doesn't play until the template is used/activated through javascript. The HTML is not to be rendered immediately when a page is loaded but maybe instantiated subsequently during runtime using JavaScript.

Template elements can be placed anywhere inside of <head>, <body>, or <frameset> and can contain any syntactically correct HTML.

The template tag helps render the repeated content through a predefined template — clone the predefined template, fill the dynamic content, and render it to the page. It can also be helpful when you want to use the same content multiple times in your HTML document without any change.

Test if the browser supports the HTML template element before activating through JavaScript.

if ('content' in document.createElement('template')) {

For example, create a template to display multiple user details on the HTML page.

Create a parent div placeholder to append the userlist

<div class="user-details--list"> </div>

Create the template to render the required user details.

<template id="template--user-details--list-item">
<div class="user-details--list-item">
<p class="user-details--list-item--fname"></p>
<p class="user-details--list-item--lname"></p>
<p class="user-details--list-item--city"></p>
<p class="user-details--list-item--state"></p>
<p class="user-details--list-item--country"></p>
</div>
</template>

Enable the JavaScript to activate the content (you can also fetch the details dynamically from an external service and render them to the page through a template)

if ('content' in document.createElement('template')) { 

var userDetailsTemplate = document.querySelector('#template--user-details--list-item');
var userDetailsList = document.querySelector(".user-details--list");

//User1

For AEM, create a client library(e.g., wknd.site.template) with the required JS(refer above)

Create a Component with the required placeholder and the template. I also include the client library at the component level; you can include it globally if needed.

<div class="user-details--list"> </div>

Now author the component to the required page. The user details will be rendered to the page(enable the necessary styling)— you can also fetch the dynamic data and render it easily through the template.

Wednesday, March 23, 2022

Editable Template Strategy — AEM(Adobe Experience Manager)

 Some of my last posts explained the Website Structure in AEM — Multi-Site Manager(MSM), Reusing the same template across multiple websites; in this post, let us discuss the Editable Template Strategy to support the multi-sites on the AEM platform.

  • How to organize the editable template?
  • Who manages the editable template?
  • Can we reuse the editable templates across multiple
  • Page properties — Page priorities on different page types, e.g., root page, product page, etc
  • Policy Variations
  • Style System Variation
  • Allowed Components
  • Theming variations — Supporting different themes.
  • Reusability
  • Impact — a dynamic connection between the page and the template is maintained; changes to the template structure will reflect any pages created with that template (initial content changes will not reflect).
  • Access management

Template Strategy:

You should be able to adopt any number of Editable template strategies; some of them are below.

  • Content Template — Template with a default header and footer and empty container between header and footer for authoring
  • Empty Template — Empty template with the container to author the components.
  • Product Template — Template to support the product pages

Template Management:

Template management is another critical factor; who manages the editable templates Development team vs. template-authors, also manage through code repository vs. directly through template editor.

  • Enable the changes through deployment; the source of truth is the git repo
  • Still enable a back sync from production author back to code repo to sync any changes enabled directly in prod author
  • Enable the changes directly through prod author; the source of truth is the prod author

Page component:

The Editable Templates are always created based on a Page Component and template type. Whenever possible, ensure the same page component is used to create the templates — some cases exception to create own page components to support unique scenarios.

Guidelines:

  • Restrict the templates to specific content paths
  • Training for template authors — Ensure the template authors are aware of the Editable template management, mainly the dynamic relationship between the Editable templates and the pages created through that — any change in the editable templates(apart from the initial content will impact the existing pages.
  • Enable the required access management for editable templates — ensure only the specific people (template-authors) have access to manage the editable templates.
  • Never enter any information that needs to be internationalized into a template. For internalization purposes, recommended using the localization feature of the Core Components.
  • Ensure template guidelines are created for authors — this will guide the template authors to use the suitable template for page creation.
  • Allow only the components enabled for authoring.