Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jekyll debug or print all variables

I want to peak into Jekyll's brain and see what's going on, in php you have get_defined_vars, so I tried to do something akin to that with:

      {% for local_variable in local_variables %}       <p> {{ local_variable }} </p><br>       {% endfor %} 

Which output nothing. Am I trying too hard? Is there some method in ruby or jekyll for this? I'd just like to poke around and make sure everything is set correctly and possibly to find out about variables I don't know about.

like image 680
thoth Avatar asked Dec 02 '15 16:12

thoth


2 Answers

With Jekyll 2.x, you can use this plugin.

It allows you to do something like {{ site | debug }}.

Since Jekyll 3, you have {{ variable | inspect }}.

like image 85
David Jacquel Avatar answered Oct 01 '22 07:10

David Jacquel


inspect doesn't let you peek inside variables, where jsonify does just that.

{{ variable | jsonify }} 

No plugins needed.

Please be aware that jsonify will use as much memory it needs to do its thing without any specific limits. Say, if you have hundreds of posts or pages, and you would want to jsonify them all at once, this may not work as you expect. Worst case the system may go out of RAM and became unresponsive. Exercise due caution.

like image 29
sanmai Avatar answered Oct 01 '22 07:10

sanmai