Example #1
0
<?php

call_user_func(function ($data) {
    add_shortcode('twig', function ($atts, $content) use(&$data) {
        $data = array_merge(Timber::get_context(), $data);
        $retr = '';
        try {
            ob_start();
            Timber::render_string($content, $data);
            $retr = ob_get_contents();
            ob_end_clean();
        } catch (Twig_Error_Loader $e) {
            return '<script>console.error("Error Loading twig string ' . $content . '")</script>';
        }
        return $retr;
    });
}, array('config' => $get_config()));
Example #2
0
 function testWithOutputBuffer()
 {
     ob_start();
     $post = $this->get_post_with_image();
     $str = '<img src="{{ post.thumbnail.src|resize(510, 280) }}" />';
     Timber::render_string($str, array('post' => $post));
     $result = ob_get_contents();
     ob_end_clean();
     $m = date('m');
     $y = date('Y');
     $this->assertEquals('<img src="http://example.org/wp-content/uploads/' . $y . '/' . $m . '/arch-510x280-c-default.jpg" />', $result);
 }
Example #3
0
/**
 * @param string $string
 * @param array $data
 * @return string
 */
function render_twig_string($string, $data = array())
{
    return Timber::render_string($string, $data);
}
Example #4
0
 function testTimberRenderString()
 {
     $pid = $this->factory->post->create(array('post_title' => 'Zoogats'));
     $post = new TimberPost($pid);
     ob_start();
     Timber::render_string('<h2>{{post.title}}</h2>', array('post' => $post));
     $data = ob_get_contents();
     ob_end_clean();
     $this->assertEquals('<h2>Zoogats</h2>', trim($data));
 }