Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

SOLVED

Can we use a data-sly-use in an html or anyother way along with an asset?

Avatar

Level 3

I would like to execute a piece of code with all dam asset resources. How can I achieve this just like we do with a cq:Page? Any suggestions appreciated

 

Thanks 

Sanjay

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I think you can do it for asset too. See this below example code snippet.

mimetype.html

<div data-sly-use.asset="com.day.cq.dam.api.Asset">
  <p>${asset.mimeType}</p>
</div>

The data-sly-use statement directs HTL to adapt the current Resource to an Asset and give it the local name asset. It then calls the getMimeType method of Asset using the HTL getter shorthand: asset.mimeType.

See this below Adobe documentation for more reference:

//https://docs.adobe.com/docs/en/htl/docs/use-api/java.html

Hope this helps!

~ Ratna.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi,

I think you can do it for asset too. See this below example code snippet.

mimetype.html

<div data-sly-use.asset="com.day.cq.dam.api.Asset">
  <p>${asset.mimeType}</p>
</div>

The data-sly-use statement directs HTL to adapt the current Resource to an Asset and give it the local name asset. It then calls the getMimeType method of Asset using the HTL getter shorthand: asset.mimeType.

See this below Adobe documentation for more reference:

//https://docs.adobe.com/docs/en/htl/docs/use-api/java.html

Hope this helps!

~ Ratna.

Avatar

Level 10

Avatar

Level 10