-
-
Save swthate/9f93e304c0b4fd7f1e12 to your computer and use it in GitHub Desktop.
Timber functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Custom Functions... **/ | |
require_once( 'lib/custom-functions.php' ); | |
/** And Now Our Regularly Scheduled Brogramming... **/ | |
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 ) { | |
$context['foo'] = 'bar'; | |
$context['stuff'] = 'I am a value set in your functions.php file'; | |
$context['notes'] = 'These values are available everytime you call Timber::get_context();'; | |
$context['menu'] = new TimberMenu(); | |
$context['site'] = $this; | |
return $context; | |
} | |
function add_to_twig( $twig ) { | |
/* this is where you can add your own fuctions to twig */ | |
$twig->addExtension( new Twig_Extension_StringLoader() ); | |
$twig->addFilter( 'myfoo', new Twig_Filter_Function( 'myfoo' ) ); | |
return $twig; | |
} | |
} | |
new StarterSite(); | |
function myfoo( $text ) { | |
$text .= ' bar!'; | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment