本文整理汇总了PHP中Timber::get_context方法的典型用法代码示例。如果您正苦于以下问题:PHP Timber::get_context方法的具体用法?PHP Timber::get_context怎么用?PHP Timber::get_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timber
的用法示例。
在下文中一共展示了Timber::get_context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFunctionsPHP
function testFunctionsPHP()
{
$context = Timber::get_context();
$this->assertEquals('StarterSite', get_class($context['site']));
$this->assertTrue(current_theme_supports('post-thumbnails'));
$this->assertEquals('bar', $context['foo']);
}
示例2: get_context
/**
* Custom implementation for get_context method.
*/
public function get_context()
{
global $content_width;
if (class_exists('Easy_Digital_Downloads')) {
global $edd_options;
}
$context = Timber::get_context();
$sidebar_primary = Timber::get_widgets('sidebar_primary');
$sidebar_footer = Timber::get_widgets('sidebar_footer');
$context['theme_mods'] = get_theme_mods();
$context['site_options'] = wp_load_alloptions();
$context['teaser_mode'] = apply_filters('maera/teaser/mode', 'excerpt');
$context['thumbnail']['width'] = apply_filters('maera/image/width', 600);
$context['thumbnail']['height'] = apply_filters('maera/image/height', 371);
$context['menu']['primary'] = has_nav_menu('primary_navigation') ? new TimberMenu('primary_navigation') : null;
$context['sidebar']['primary'] = apply_filters('maera/sidebar/primary', $sidebar_primary);
$context['sidebar']['footer'] = apply_filters('maera/sidebar/footer', $sidebar_footer);
$context['pagination'] = Timber::get_pagination();
$context['comment_form'] = TimberHelper::get_comment_form();
$context['comments_args'] = array('style' => 'ul', 'reply_text' => __('Reply', 'maera'), 'short_ping' => true, 'avatar_size' => 60);
$context['site_logo'] = get_option('site_logo', false);
$context['content_width'] = $content_width;
$context['sidebar_template'] = maera_templates_sidebar();
if (class_exists('Easy_Digital_Downloads')) {
$data['edd_options'] = $edd_options;
$data['download_categories'] = Timber::get_terms('download_category');
$data['download_tags'] = Timber::get_terms('download_tag');
$data['default_image'] = new TimberImage(get_template_directory_uri() . '/assets/images/default.png');
}
return apply_filters('maera/timber/context', $context);
}
示例3: form
public function form($instance)
{
$context = \Timber::get_context();
$context['title'] = !empty($instance['title']) ? $instance['title'] : __('Test', self::I18N_DOMAIN);
$context['widget'] = $this;
\Timber::render('timber-test-widget-form.twig', $context);
}
示例4: load_view
public function load_view()
{
$context = Timber::get_context();
$context['data'] = $this->data;
$context['constants'] = get_slate_constants();
Timber::render(theme_views . '/single.twig', $context);
}
示例5: 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);
}
示例6: testGetData
function testGetData()
{
$_GET['foo'] = 'bar';
$template = '{{request.get.foo}}';
$context = Timber::get_context();
$str = Timber::compile_string($template, $context);
$this->assertEquals('bar', $str);
}
示例7: getCallback
/**
*
* {$inheritdoc}
*
*/
public function getCallback()
{
$context = \Timber::get_context();
$context['options'] = $this->getOptions();
$context['field_name'] = self::META_NAME_PAGE_TYPE;
$context['current_value'] = $this->getCurrentValue();
\Timber::render($this->dic['CMS']->getViewPath('meta_boxes/page-type.html.twig'), $context);
}
示例8: testTimberContext
function testTimberContext()
{
add_filter('timber/context', function ($context) {
$context['person'] = "Nathan Hass";
return $context;
});
$context = Timber::get_context();
$this->assertEquals('Nathan Hass', $context['person']);
}
示例9: twig_replacements
/**
* Get the twig file and pass the replacement to it.
* This function is just a helper for the do_twig_replacements function.
*/
public function twig_replacements($replacement = false)
{
// If no replacement has been defined, exit.
if (!$replacement) {
return;
}
$context = Timber::get_context();
$context['element'] = $replacement;
Timber::render(array('twig-str_replace.twig'), $context, Maera()->cache->cache_duration());
}
示例10: menuPageCallback
/**
*
* Callback methods for the options page
*
* @author Tim Perry
*
*/
public function menuPageCallback()
{
$args = array('public' => true);
$context = \Timber::get_context();
$context['postTypes'] = get_post_types($args, 'names');
$context['settingsGroupName'] = self::SETTINGS_GROUP_NAME;
$context['fieldName'] = self::OPTION_NAME_SHOW_ON;
$context['currentValue'] = get_option(self::OPTION_NAME_SHOW_ON);
\Timber::render($this->getPath() . '/views/options-page.twig', $context);
}
示例11: testContextLoop
/**
* This throws an infite loop if memorization isn't working
*/
function testContextLoop()
{
add_filter('timber_context', function ($context) {
$context = Timber::get_context();
$context['zebra'] = 'silly horse';
return $context;
});
$context = Timber::get_context();
$this->assertEquals('http://example.org', $context['http_host']);
}
示例12: testPHPSidebar
function testPHPSidebar()
{
add_filter('timber_context', function ($context) {
$context['sidebar'] = Timber::get_sidebar('assets/my-sidebar.php');
return $context;
});
$context = Timber::get_context();
$result = Timber::compile('assets/main-w-sidebar-php.twig', $context);
$this->assertEquals("A Fever You Can't Sweat Out by Panic! at the Disco from 2005", trim($result));
}
示例13: testFunctionsPHP
function testFunctionsPHP()
{
self::_setupStarterTheme();
require_once get_template_directory() . '/functions.php';
$context = Timber::get_context();
$this->assertEquals('StarterSite', get_class($context['site']));
$this->assertTrue(current_theme_supports('post-thumbnails'));
$this->assertEquals('bar', $context['foo']);
switch_theme('twentythirteen');
}
示例14: testTwigSidebar
function testTwigSidebar()
{
$context = Timber::get_context();
$sidebar_post = $this->factory->post->create(array('post_title' => 'Sidebar post content'));
$sidebar_context = array();
$sidebar_context['post'] = new TimberPost($sidebar_post);
$context['sidebar'] = Timber::get_sidebar('assets/sidebar.twig', $sidebar_context);
$result = Timber::compile('assets/main-w-sidebar.twig', $context);
$this->assertEquals('I am the main stuff <h4>Sidebar post content</h4>', trim($result));
}
示例15: get_filtered_context
/**
* Returns filtered Timber Context
*
* @param array $args Elements to be filtered.
* @param bool $override_with_empty Whether to override default when empty is provided.
* @return array
*/
public function get_filtered_context($args = false, $override_with_empty = true)
{
if (!$override_with_empty) {
$args = $this->remove_empty($args);
}
$this->setup_filters($args);
$context = Timber::get_context();
$context = $this->add_context_elements($context);
$this->remove_filters($args);
return $context;
}