示例#1
0
 function testTwigLoadsFromAlternateDirName()
 {
     Timber::$dirname = array('foo', 'views');
     if (!file_exists(get_template_directory() . '/foo')) {
         mkdir(get_template_directory() . '/foo', 0777, true);
     }
     copy(__DIR__ . '/assets/single-foo.twig', get_template_directory() . '/foo/single-foo.twig');
     $str = Timber::compile('single-foo.twig');
     $this->assertEquals('I am single-foo', trim($str));
 }
示例#2
0
<?php

if (!class_exists('Timber')) {
    add_action('admin_notices', function () {
        echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url(admin_url('plugins.php#timber')) . '">' . esc_url(admin_url('plugins.php')) . '</a></p></div>';
    });
    return;
}
Timber::$dirname = array('templates', 'views');
class StarterSite extends TimberSite
{
    function __construct()
    {
        add_theme_support('post-formats');
        add_theme_support('post-thumbnails');
        add_theme_support('menus');
        add_filter('timber_context', array($this, 'add_to_context'));
        add_filter('get_twig', array($this, 'add_to_twig'));
        add_action('init', array($this, 'register_post_types'));
        add_action('init', array($this, 'register_taxonomies'));
        parent::__construct();
    }
    function register_post_types()
    {
        //this is where you can register custom post types
    }
    function register_taxonomies()
    {
        //this is where you can register custom taxonomies
    }
    function add_to_context($context)
示例#3
0
Description: The WordPress Timber Library allows you to write themes using the power Twig templates.
Plugin URI: http://timber.upstatement.com
Author: Jared Novack + Upstatement
Version: 0.22.2
Author URI: http://upstatement.com/
*/
global $wp_version;
global $timber;
// we look for Composer files first in the plugins dir.
// then in the wp-content dir (site install).
// and finally in the current themes directories.
if (file_exists($composer_autoload = __DIR__ . '/vendor/autoload.php') || file_exists($composer_autoload = WP_CONTENT_DIR . '/vendor/autoload.php') || file_exists($composer_autoload = plugin_dir_path(__FILE__) . 'vendor/autoload.php') || file_exists($composer_autoload = get_stylesheet_directory() . '/vendor/autoload.php') || file_exists($composer_autoload = get_template_directory() . '/vendor/autoload.php')) {
    require_once $composer_autoload;
}
$timber = new Timber();
Timber::$dirname = 'views';
/**
 * Timber Class.
 *
 * Main class called Timber for this plugin.
 *
 * Usage:
 *  $posts = Timber::get_posts();
 *  $posts = Timber::get_posts('post_type = article')
 *  $posts = Timber::get_posts(array('post_type' => 'article', 'category_name' => 'sports')); // uses wp_query format.
 *  $posts = Timber::get_posts(array(23,24,35,67), 'InkwellArticle');
 *
 *  $context = Timber::get_context(); // returns wp favorites!
 *  $context['posts'] = $posts;
 *  Timber::render('index.twig', $context);
 */
            return "desktop";
        } else {
            return "mobile";
        }
    }
}
if ($detect->isTablet()) {
    // If tablet
    array_unshift($template_array, $template_base . '/tablet');
} else {
    if (!$detect->isMobile()) {
        // If not tablet and not mobile
        array_unshift($template_array, $template_base . '/desktop', $template_base . '/tablet');
    }
}
Timber::$dirname = $template_array;
class StarterSite extends TimberSite
{
    function __construct()
    {
        load_theme_textdomain('nilslindstrom-theme', get_template_directory() . '/languages');
        add_theme_support('automatic-feed-links');
        add_theme_support('title-tag');
        add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption'));
        add_theme_support('post-formats', array('aside', 'image', 'video', 'quote', 'link'));
        add_theme_support('post-thumbnails');
        add_theme_support('menus');
        register_nav_menus(array('primary' => esc_html__('Primary', 'theme'), 'footer' => esc_html__('Footer', 'theme')));
        add_filter('timber_context', array($this, 'add_to_context'));
        add_filter('get_twig', array($this, 'add_to_twig'));
        add_action('init', array($this, 'register_post_types'));
示例#5
0
<?php

require_once __DIR__ . '/wp/acf-blog-options.php';
require_once __DIR__ . '/wp/acf-hacks.php';
if (class_exists('Timber')) {
    require_once 'wp/portfolio-entry.php';
    require_once 'wp/blades-site.php';
}
if (file_exists(__DIR__ . '/vendor/jarednova/mesh/mesh.php')) {
    require_once 'vendor/jarednova/mesh/mesh.php';
}
Timber::$dirname = array('views', 'pm-home');
require_once 'pm-home/PHProjects.php';
new PH_Projects();
ACFHacks::map_page_rule_to_slug(48, 'about');
ACFHacks::map_page_rule_to_slug(506, 'careers');
ACFHacks::map_page_rule_to_slug(2777, 'jobs');
ACFHacks::map_page_rule_to_slug(2995, 'drinks');
ACFHacks::map_page_rule_to_slug(4883, 'garage');
ACFHacks::map_page_rule_to_slug(4913, 'timber');
add_theme_support('menus');
add_theme_support('post-thumbnails');
add_filter('timber_context', function ($data) {
    $data['menu'] = new TimberMenu();
    global $post;
    if ($post && isset($post->ID)) {
        $maybe_title = get_post_meta($post->ID, 'custom_title_tag', true);
        if ($maybe_title) {
            $data['wp_title'] = $maybe_title;
        }
    }
示例#6
0
<?php

if (WP_DEBUG) {
    header("Access-Control-Allow-Origin: *");
}
if (!class_exists("Timber")) {
    add_action("admin_notices", function () {
        echo "<div class=\"error\"><p>Timber is not activated. Make sure you activate the plugin in\n    <a href=\"" . esc_url(admin_url("plugins.php#timber")) . "\">" . esc_url(admin_url("plugins.php")) . "</a>.</p></div>";
    });
    return;
}
Timber::$dirname = "templates";
class MyTimberSite extends TimberSite
{
    function __construct()
    {
        add_theme_support("post-formats");
        add_theme_support("post-thumbnails");
        add_theme_support("menus");
        add_action("init", array($this, "register_post_types"));
        add_action("init", array($this, "register_taxonomies"));
        add_action("wp_enqueue_scripts", array($this, "enqueue_scripts"));
        add_filter("timber_context", array($this, "add_to_context"));
        add_filter("get_twig", array($this, "add_to_twig"));
        parent::__construct();
    }
    function register_post_types()
    {
        // This is where you can register custom post types
    }
    function register_taxonomies()
/**
 * MANAGE TIMBER INITIALIZATION
 * * check whether Timber is activated
 * * configure custom TimberSite class
 * * initialize LegacyPartners instance
 * @note - Manage Timber context in add_to_context()
 * @note - Extend Twig instance in add_to_twig()
 */
if (!class_exists('Timber')) {
    add_action('admin_notices', function () {
        echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url(admin_url('plugins.php#timber')) . '">' . esc_url(admin_url('plugins.php')) . '</a></p></div>';
    });
    return;
}
Timber::$dirname = array('templates', 'templates/structures');
class LegacyParnters extends TimberSite
{
    function __construct()
    {
        add_theme_support('post-formats');
        add_theme_support('post-thumbnails');
        add_theme_support('menus');
        add_filter('timber_context', array($this, 'add_to_context'));
        add_filter('get_twig', array($this, 'add_to_twig'));
        add_action('init', array($this, 'register_post_types'));
        add_action('init', array($this, 'register_taxonomies'));
        parent::__construct();
    }
    function add_to_context($context)
    {
示例#8
0
<?php

if (!class_exists('Timber')) {
    add_action('admin_notices', function () {
        echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url(admin_url('plugins.php#timber')) . '">' . esc_url(admin_url('plugins.php')) . '</a></p></div>';
    });
    return;
}
Timber::$dirname = array('views');
class StarterSite extends TimberSite
{
    function __construct()
    {
        add_filter('timber_context', array($this, 'add_to_context'));
        parent::__construct();
    }
    function add_to_context($context)
    {
        $context['main_menu'] = new TimberMenu('primary_navigation');
        $context['site'] = $this;
        $context['options'] = get_fields('option');
        return $context;
    }
}
new StarterSite();
示例#9
0
            // have a good config, lets update tranient values
            if (is_array($config) && count($errors) === 0) {
                set_transient('fg_config', $config, 0);
                set_transient('fg_config_timestamp', $filetime, 0);
            } else {
                //means an error in yaml settings. -- need a way to notify user it failed
                $config = $cache['config'];
            }
        } else {
            $config = $cache['config'];
        }
        //adding errors
        $config['ERRORS'] = $errors;
        $dirnameChildTheme = get_stylesheet_directory() . '/twig-templates';
        $dirnameTheme = get_template_directory() . '/twig-templates';
        Timber::$dirname = array('twig-templates');
        //setting up timber twig file locations
        // it will look in theme first, if it doesn't find it it will look in master
        $timberLocationsArray = array($dirnameChildTheme, $dirnameChildTheme . '/wp', $dirnameChildTheme . '/partials', $dirnameChildTheme . '/email', $dirnameChildTheme . '/form');
        // only merge if seperate;
        if ($dirnameChildTheme !== $dirnameTheme) {
            $timberLocationsArray = array_merge($timberLocationsArray, array($dirnameTheme, $dirnameTheme . '/wp', $dirnameTheme . '/partials', $dirnameTheme . '/email', $dirnameTheme . '/form'));
        }
        // adding filter to add twig locations
        $timberLocationsArray = apply_filters('fg_theme_master_twig_locations', $timberLocationsArray);
        Timber::$locations = $timberLocationsArray;
        return $config;
    };
});
$get_slideshow = function () {
    if (function_exists('rwmb_meta')) {
示例#10
0
<?php

// Timber::$cache = true;
Timber::$dirname = ['views', 'views/templates'];
require_once 'lumberjack/bootstrap.php';
示例#11
0
<?php

namespace WPSW\ThemeSetup\Template;

use Yare\Yare;
$timber = new \Timber\Timber();
\Timber::$dirname = Yare::config('paths.template');
function template_render()
{
    //$app = new \Yare\App();
    //$app->run();
    $loader = \Yare\Autoloader::instance();
    pc($loader, 'loader');
    $ViewClass = $loader->view();
    $view = new $ViewClass();
    $view->render();
}
add_action('yare/template_render', __NAMESPACE__ . '\\template_render');
function add_to_twig($twig)
{
    $filters = Yare::config('theme.filters');
    foreach ($filters as $filter => $callback) {
        $twig->addFilter($filter, new \Twig_SimpleFilter($filter, $callback));
    }
    $functions = Yare::config('theme.functions');
    foreach ($functions as $function => $callback) {
        $twig->addFunction($function, new \Twig_SimpleFunction($function, $callback));
    }
    return $twig;
}
add_filter('get_twig', __NAMESPACE__ . '\\add_to_twig');