k-isabelle
5/31/2018 - 4:29 PM

Output Timber Context Into Console

var jsonify = $('.jsonify');

jsonify.each( (index, currentElement) => {
  try {
    console.log(JSON.parse(currentElement.innerHTML));
  } catch (error) {
    console.log(currentElement.id + ' cannot be parsed.');
  }
});
<?php
  $context         = Timber::get_context();
  $content_blocks  = get_field('content_blocks');
?>

<pre id="header-context" class="jsonify">
  <?php echo esc_html(json_encode($context));?>
</pre>
    
<pre id="content-blocks" class="jsonify">
  <?php echo esc_html(json_encode($content_blocks)); ?>
</pre>