-
-
Save bmvakili/b5d871b4cbc4ebbbe0a0 to your computer and use it in GitHub Desktop.
Dump Liferay 7 GA4 variables in Freemarker - adapted from James Falkner's original
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#attempt> | |
<#assign black_list = ["class", "request", "getreader", "getinputstream", "writer"] /> | |
<#macro dump key data> | |
<#if data?is_enumerable> | |
<p><b>${key}</b> | |
<@printList data,[] /> | |
<#elseif data?is_hash_ex> | |
<p><b>${key}</b> | |
<@printHashEx data,[] /> | |
<#else> | |
<p><@printItem data?if_exists,[], key, false /></#if> | |
</#macro> | |
<#macro printList list has_next_array> | |
<#local counter=0 /> | |
<#list list as item> | |
<#list has_next_array+[true] as has_next><#if !has_next> <#else> | </#if></#list> | |
<#list has_next_array as has_next><#if !has_next> <#else> | </#if></#list><#t> | |
<#t><@printItem item?if_exists,has_next_array+[item_has_next], counter, false /> | |
<#local counter = counter + 1/> | |
</#list> | |
</#macro> | |
<#macro printHashEx hash has_next_array> | |
= <code>${(hash.data!(hash.toString()))!"No String Representation"}</code> | |
<ul>Callable methods: | |
<ul> | |
<#list hash?keys as key> | |
<#list has_next_array+[true] as has_next><#if !has_next> <#else> | </#if></#list> | |
<#list has_next_array as has_next><#if !has_next> <#else> | </#if></#list><#t> | |
${key} | |
</#list> | |
</ul> | |
</ul> | |
</#macro> | |
<#macro printHashExFull hash has_next_array> | |
<#list hash?keys as key> | |
<#list has_next_array+[true] as has_next><#if !has_next> <#else> | </#if></#list> | |
<#list has_next_array as has_next><#if !has_next> <#else> | </#if></#list><#t> | |
<#t><#attempt><@printItem hash[key]?if_exists,has_next_array+[key_has_next], key, true /><#recover><pre>${.error}</pre></#recover> | |
</#list> | |
</#macro> | |
<#macro printItem item has_next_array key full> | |
<#if item?is_method> | |
+- <b>${key}</b> = ?? (method) | |
<#elseif item?is_enumerable> | |
+- <b>${key}</b> | |
<@printList item, has_next_array /><#t> | |
<#elseif item?is_hash_ex && omit(key?string)><#-- omit bean-wrapped java.lang.Class objects --> | |
+- <b>${key}</b> (omitted) | |
<#elseif item?is_hash_ex> | |
+- <b>${key}</b> | |
<#if full> | |
<@printHashExFull item, has_next_array /><#t> | |
<#else> | |
<@printHashEx item, has_next_array /><#t> | |
</#if> | |
<#elseif item?is_number> | |
+- <b>${key}</b> = <code>${item}</code> | |
<#elseif item?is_string> | |
+- <b>${key}</b> = <code>"${item}"</code> | |
<#elseif item?is_boolean> | |
+- <b>${key}</b> = <code>${item?string}</code> | |
<#elseif item?is_date> | |
+- <b>${key}</b> = <code>${item?string("yyyy-MM-dd HH:mm:ss zzzz")}</code> | |
<#elseif item?is_transform> | |
+- <b>${key}</b> = ?? (transform) | |
<#elseif item?is_macro> | |
+- <b>${key}</b> = ?? (macro) | |
<#elseif item?is_hash> | |
+- <b>${key}</b> = ?? (hash) | |
<#elseif item?is_node> | |
+- <b>${key}</b> = ?? (node) | |
</#if> | |
</#macro> | |
<#function omit key> | |
<#local what = key?lower_case> | |
<#list black_list as item> | |
<#if what?index_of(item) gte 0> | |
<#return true> | |
</#if> | |
</#list> | |
<#return false> | |
</#function> | |
<h1>All Liferay Variables</h1> | |
<em>See the bottom for the <code>request</code> variable expansion</em> | |
<hr> | |
<#list .data_model?keys as var> | |
<#if var?index_of("writer") lt 0> | |
<@dump var,.data_model[var] /> | |
</#if> | |
</#list> | |
<hr> | |
<h1>The <code>request</code> object</h1> | |
<pre> | |
<@printHashExFull request,[] /> | |
</pre> | |
<#recover> | |
<pre> | |
${.error} | |
</pre> | |
</#recover> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A way I found to get it work is substituting line 108 with
even if the printed object is really huge!