HTL: How to dump the contents of my variable? | Community
Skip to main content
jayv25585659
Level 8
March 5, 2018
Question

HTL: How to dump the contents of my variable?

  • March 5, 2018
  • 4 replies
  • 2383 views

So I have this line in my HTML

<sly data-sly-use.menuItem="${'com.myhost.core.impl.view.global.TopNavigationItemView'}"></sly>

menuItem has many properties like id, activeclass and etc.

I would like to dump/show the full contents of menuItem without having to specify the properties (example: menuItem.id) individually.

Is this possible? If yes, how?

I tried this

<dl data-sly-list="${menuItem}">

    <dt>index: ${itemList.index}</dt>

    <dd>value: ${item.title}</dd>

</dl>

but I cannot see it in my page. I even tried "view page source" and nothing there.

Any ideas? Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

navinkaushal
Level 4
March 5, 2018

You may need to create a new method in your Use Class as follows:

public String variableDump() {

  return new ToStringBuilder(this).

// All your variables

  append("name", name).

  append("age", age).

  append("smoker", smoker).

  toString();

  }

Then you can call this function in your HTL Template to dump all the variables.

jayv25585659
Level 8
March 6, 2018

why that would work for a custom class? what happens if I want to dump the contents of AEM built-in variables like $properties/$pageProperties?

Thanks

navinkaushal
Level 4
March 6, 2018

Did you forget the concept of Encapsulation???

If you can get a dump of properties (which may be protected or private) then what is the benefit of encapsulation???

Hemant_arora
Level 8
March 6, 2018

try this example in sample6

HTL introduction part 1

  • inside a data-sly-list you have access to a list-variable that contain things like : index, count, odd, even, first, last, middle
  • in the expression you see the use of the ternary operator