本文整理汇总了PHP中Timber::compile_string方法的典型用法代码示例。如果您正苦于以下问题:PHP Timber::compile_string方法的具体用法?PHP Timber::compile_string怎么用?PHP Timber::compile_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timber
的用法示例。
在下文中一共展示了Timber::compile_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTermToString
function testTermToString()
{
$term_id = $this->factory->term->create(array('name' => 'New England Patriots'));
$term = new TimberTerm('new-england-patriots');
$str = Timber::compile_string('{{term}}', array('term' => $term));
$this->assertEquals('New England Patriots', $str);
}
示例2: testTwigFilterDateWordPressOption
function testTwigFilterDateWordPressOption()
{
$format = get_option('date_format');
$str = Timber::compile_string("{{now|date('" . $format . "')}}");
$empty = Timber::compile_string("{{now|date}}");
$this->assertSame($str, $empty);
}
示例3: testACFGetFieldTermTag
function testACFGetFieldTermTag()
{
$tid = $this->factory->term->create();
update_field('color', 'green', 'post_tag_' . $tid);
$term = new TimberTerm($tid);
$str = '{{term.color}}';
$this->assertEquals('green', Timber::compile_string($str, array('term' => $term)));
}
示例4: testLinkOnSubdirectoryInstall
function testLinkOnSubdirectoryInstall()
{
update_option('siteurl', 'http://example.org/wordpress', true);
$context = Timber::get_context();
$theme = $context['site']->theme;
$output = Timber::compile_string('{{site.theme.link}}', $context);
$this->assertEquals('http://example.org/wp-content/themes/' . $theme->slug, $output);
}
示例5: testGetData
function testGetData()
{
$_GET['foo'] = 'bar';
$template = '{{request.get.foo}}';
$context = Timber::get_context();
$str = Timber::compile_string($template, $context);
$this->assertEquals('bar', $str);
}
示例6: testTypeMethodInTwigLabels
function testTypeMethodInTwigLabels()
{
$post_id = $this->factory->post->create();
$post = new TimberPost($post_id);
$template = '{{post.type.labels.name}}';
$str = Timber::compile_string($template, array('post' => $post));
$this->assertEquals('Posts', $str);
}
示例7: testPreviewWithSpaceInMoreTag
function testPreviewWithSpaceInMoreTag()
{
$pid = $this->factory->post->create(array('post_content' => 'Lauren is a duck, but a great duck let me tell you why <!--more--> Lauren is not a duck', 'post_excerpt' => ''));
$post = new TimberPost($pid);
$template = '{{post.preview.length(3).force}}';
$str = Timber::compile_string($template, array('post' => $post));
$this->assertEquals('Lauren is a… <a href="' . $post->link() . '" class="read-more">Read More</a>', $str);
}
示例8: testImageResizeRetinaFilterNotAnImage
function testImageResizeRetinaFilterNotAnImage()
{
self::enable_error_log(false);
$str = 'Image? {{"/wp-content/uploads/2016/07/stuff.jpg"|retina(3)}}';
$compiled = Timber::compile_string($str);
$this->assertEquals('Image? /wp-content/uploads/2016/07/stuff.jpg', $compiled);
self::enable_error_log(true);
}
示例9: testPostCustomFieldPropertyConflict
function testPostCustomFieldPropertyConflict()
{
$post_id = $this->factory->post->create(array('post_title' => 'foo'));
update_post_meta($post_id, 'post_title', 'bar');
$post = new TimberPost($post_id);
$str = '{{post.title}}';
$result = Timber::compile_string($str, array('post' => $post));
$this->assertEquals('foo', $result);
}
示例10: testUnderscoreTypeCustomField
function testUnderscoreTypeCustomField()
{
$post_id = $this->factory->post->create();
update_post_meta($post_id, '_type', 'numberwang');
$post = new TimberPost($post_id);
$template = '{{post._type}}';
$str = Timber::compile_string($template, array('post' => $post));
$this->assertEquals('numberwang', $str);
}
示例11: testModifiedTimeFilter
function testModifiedTimeFilter()
{
$pid = $this->factory->post->create();
$post = new TimberPost($pid);
add_filter('get_the_modified_time', function ($the_date) {
return 'foobar';
});
$twig = "I was modified {{post.modified_time('F j, Y @ g:i a')}}";
$str = Timber::compile_string($twig, array('post' => $post));
$this->assertEquals('I was modified foobar', $str);
}
示例12: testDescription
function testDescription()
{
$uid = $this->factory->user->create(array('display_name' => 'Baberaham Lincoln'));
update_user_meta($uid, 'description', 'Sixteenth President');
$user = new TimberUser($uid);
$this->assertEquals('Sixteenth President', $user->description);
$pid = $this->factory->post->create(array('post_author' => $uid));
$post = new TimberPost($pid);
$str = Timber::compile_string('{{post.author.description}}', array('post' => $post));
$this->assertEquals('Sixteenth President', $str);
}
示例13: testJPEGtoJPG
function testJPEGtoJPG()
{
$filename = TestTimberImage::copyTestImage('jarednova.jpeg');
$str = Timber::compile_string('{{file|tojpg}}', array('file' => $filename));
$renamed = str_replace('.jpeg', '.jpg', $filename);
$this->assertFileExists($renamed);
$this->assertGreaterThan(1000, filesize($renamed));
$this->assertEquals('image/jpeg', mime_content_type($filename));
$this->assertEquals('image/jpeg', mime_content_type($renamed));
unlink($filename);
unlink($renamed);
}
示例14: testCommentWithChildren
function testCommentWithChildren()
{
$kramer = $this->factory->user->create(array('display_name' => 'Cosmo Kramer'));
$post_id = $this->factory->post->create();
$comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'These pretzels are making me thirsty.', 'user_id' => $kramer));
sleep(2);
$comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'Perhaps there’s more to Newman than meets the eye.'));
$child_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'No, there’s less.', 'comment_parent' => $comment_id));
$post = new TimberPost($post_id);
$comments = $post->get_comments();
$this->assertEquals(2, count($comments));
$this->assertEquals(1, count($comments[1]->children));
$twig_string = '{{comment.author.name}}';
$result = Timber::compile_string($twig_string, array('comment' => $comments[0]));
$this->assertEquals('Cosmo Kramer', $result);
}
示例15: testImageResizeRetinaFilter
function testImageResizeRetinaFilter()
{
$filename = TestTimberImage::copyTestImage('eastern.jpg');
$wp_filetype = wp_check_filetype(basename($filename), null);
$post_id = $this->factory->post->create();
$attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_excerpt' => '', 'post_status' => 'inherit');
$attach_id = wp_insert_attachment($attachment, $filename, $post_id);
add_post_meta($post_id, '_thumbnail_id', $attach_id, true);
$data = array();
$data['post'] = new TimberPost($post_id);
$str = '{{post.thumbnail.src|resize(100, 50)|retina(3)}}';
$compiled = Timber::compile_string($str, $data);
$img = new TimberImage($compiled);
$this->assertContains('@3x', $compiled);
$this->assertEquals(300, $img->width());
}