The Magic Template Variable Dumper Script for Liferay 7

You may recall back in February 2014 I published a FreeMarker script that would dump variables from WCM and ADT Templates in Liferay 6.2. Well, it's back, this time for Liferay 7! I tweaked it a bit to show the hierarchy of the request object a bit better and added a recursion depth variable to control how deep down the rabbit hole you go (if you are feeling a bit cold during winter, feel free to set that value up above 5 and gather around your CPU to get warm).

How to use

Just create a web content structure and template, paste this code into the template, then publish an article using that structure and template.

Here's what it looks like:

 

And here's the request variable expansion (from the themeDisplay map)

 

Note it expands almost everything, so you can see embedded portlets, layouts, OSGi services, etc. It's quite interesting to see what one can get at :)

Show me the code!

Find the code below. I'm just waiting for someone to make this look awesome (looking at you, frontend people).

Happy hacking!

Blogs
I get the following error from this. Any suggestions?

An error has occurred when reading existing sub-variable "parts"; see cause exception! The type of the containing value was: extended_hash+string (com.liferay.portlet.PortletServletRequest wrapped into f.e.b.StringModel)

----
FTL stack trace ("~" means nesting-related):
- Failed at: @printItem hash[key]!, has_next_array... [in template "20202#20246#34008" in macro "printHashExFull" at line 78, column 9]
- Reached through: @printHashExFull request, [], 0 [in template "20202#20246#34008" at line 151, column 1]
----

I get the same error of Stephen. Why?

 

 

An error has occurred when reading existing sub-variable "reader"; see cause exception! The type of the containing value was: extended_hash+string (com.liferay.portal.kernel.servlet.ProtectedServletRequest wrapped into f.e.b.StringModel) ---- FTL stack trace ("~" means nesting-related): - Failed at: @printItem hash[key]!, has_next_array... [in template "20099#20135#71222" in macro "printHashExFull" at line 78, column 9] - Reached through: @printHashExFull request, [], 0 [in template "20099#20135#71222" at line 151, column 1] ----