Expand my Community achievements bar.

SOLVED

How to include Static HTML in an AEM component.

Avatar

Level 2

How do to include static HTML page in a component. The page can be within AEM site context or as an asset .html file

 

Thanks

Ani

 

1 Accepted Solution

Avatar

Correct answer by
Level 5

If the author needs to upload JS & CSS, I highly suggest to reconsider the requirement as the author shouldn't be dealing with code, doesn't sound like a good practice.

 

However, technically you can do this using the embed core component, as @arunpatidar mentioned, which allows the author to put in HTML and even JS/CSS by adding them in HTML markup itself:

Screen Shot 2022-07-28 at 1.42.40 pm.png

https://experienceleague.adobe.com/docs/experience-manager-core-components/using/components/embed.ht...

 

View solution in original post

6 Replies

Avatar

Community Advisor

hi @ajoshi84 

you can create a raw html component / free form html component  to display the static html in it. Component's dialog will have a text area to place the html, along with hardcoded styles and js.

Avatar

Community Advisor

Hi @ajoshi84 ,

I would use data-sly-include

data-sly-include replaces the content of the host element with the markup generated by the indicated HTML template file (HTL, JSP, ESP etc.) when it is processed by its corresponding template engine. The rendering context of the included file will not include the current HTL context (that of the including file); Consequently, for inclusion of HTL files, the current data-sly-use would have to be repeated in the included file (In such a case it is usually better to use data-sly-template and data-sly-call)

A simple include:

<section data-sly-include="path/to/template.html"></section>

JSPs can be included the same way:

<section data-sly-include="path/to/template.jsp"></section>

Options let you manipulate the path of the file:

<section data-sly-include="${ @ file='path/to/template.html'}"></section>
<section data-sly-include="${'template.html' @ prependPath='my/path'}"></section>
<section data-sly-include="${'my/path' @ appendPath='template.html'}"></section>

You can also change the WCM mode:

<section data-sly-include="${'template.html' @ wcmmode='disabled'}"></section>

Hope that helps!

Regards,

Santosh

Avatar

Level 5

- To include an HTML file in a component, use data-sly-include:

Screen Shot 2022-07-27 at 10.25.50 am.png

 

- To include a cq:page in a component, use data-sly-resource:

Screen Shot 2022-07-27 at 10.32.08 am.png

Avatar

Level 3

In this scenario, what if author want to upload a complete HTML structure with its related js/css in AEM? 

 

Thanks

Anika

Avatar

Correct answer by
Level 5

If the author needs to upload JS & CSS, I highly suggest to reconsider the requirement as the author shouldn't be dealing with code, doesn't sound like a good practice.

 

However, technically you can do this using the embed core component, as @arunpatidar mentioned, which allows the author to put in HTML and even JS/CSS by adding them in HTML markup itself:

Screen Shot 2022-07-28 at 1.42.40 pm.png

https://experienceleague.adobe.com/docs/experience-manager-core-components/using/components/embed.ht...

 

Avatar

Community Advisor

Hi,

You can use embed component for core component to include HTML in your page 

https://www.aemcomponents.dev/content/core-components-examples/library/core-content/embed.html

 

You must not upload include css or js directly. CSS and JS should be part of clientlibs.



Arun Patidar