|
7 | 7 | // Load Composer dependencies. |
8 | 8 | require_once __DIR__ . '/vendor/autoload.php'; |
9 | 9 |
|
| 10 | +require_once __DIR__ . '/src/StarterSite.php'; |
| 11 | + |
10 | 12 | Timber\Timber::init(); |
11 | 13 |
|
12 | | -/** |
13 | | - * Sets the directories (inside your theme) to find .twig files |
14 | | - */ |
| 14 | +// Sets the directories (inside your theme) to find .twig files. |
15 | 15 | Timber::$dirname = [ 'templates', 'views' ]; |
16 | 16 |
|
17 | | -/** |
18 | | - * By default, Timber does NOT autoescape values. Want to enable Twig's autoescape? |
19 | | - * No prob! Just set this value to true |
20 | | - */ |
21 | | -Timber::$autoescape = false; |
22 | | - |
23 | | -/** |
24 | | - * We're going to configure our theme inside of a subclass of Timber\Site |
25 | | - * You can move this to its own file and include here via php's include("MySite.php") |
26 | | - */ |
27 | | -class StarterSite extends Timber\Site { |
28 | | - /** Add timber support. */ |
29 | | - public function __construct() { |
30 | | - add_action( 'after_setup_theme', array( $this, 'theme_supports' ) ); |
31 | | - add_filter( 'timber/context', array( $this, 'add_to_context' ) ); |
32 | | - add_filter( 'timber/twig', array( $this, 'add_to_twig' ) ); |
33 | | - add_action( 'init', array( $this, 'register_post_types' ) ); |
34 | | - add_action( 'init', array( $this, 'register_taxonomies' ) ); |
35 | | - parent::__construct(); |
36 | | - } |
37 | | - /** This is where you can register custom post types. */ |
38 | | - public function register_post_types() { |
39 | | - |
40 | | - } |
41 | | - /** This is where you can register custom taxonomies. */ |
42 | | - public function register_taxonomies() { |
43 | | - |
44 | | - } |
45 | | - |
46 | | - /** This is where you add some context |
47 | | - * |
48 | | - * @param string $context context['this'] Being the Twig's {{ this }}. |
49 | | - */ |
50 | | - public function add_to_context( $context ) { |
51 | | - $context['foo'] = 'bar'; |
52 | | - $context['stuff'] = 'I am a value set in your functions.php file'; |
53 | | - $context['notes'] = 'These values are available everytime you call Timber::context();'; |
54 | | - $context['menu'] = Timber::get_menu(); |
55 | | - $context['site'] = $this; |
56 | | - return $context; |
57 | | - } |
58 | | - |
59 | | - public function theme_supports() { |
60 | | - // Add default posts and comments RSS feed links to head. |
61 | | - add_theme_support( 'automatic-feed-links' ); |
62 | | - |
63 | | - /* |
64 | | - * Let WordPress manage the document title. |
65 | | - * By adding theme support, we declare that this theme does not use a |
66 | | - * hard-coded <title> tag in the document head, and expect WordPress to |
67 | | - * provide it for us. |
68 | | - */ |
69 | | - add_theme_support( 'title-tag' ); |
70 | | - |
71 | | - /* |
72 | | - * Enable support for Post Thumbnails on posts and pages. |
73 | | - * |
74 | | - * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ |
75 | | - */ |
76 | | - add_theme_support( 'post-thumbnails' ); |
77 | | - |
78 | | - /* |
79 | | - * Switch default core markup for search form, comment form, and comments |
80 | | - * to output valid HTML5. |
81 | | - */ |
82 | | - add_theme_support( |
83 | | - 'html5', |
84 | | - array( |
85 | | - 'comment-form', |
86 | | - 'comment-list', |
87 | | - 'gallery', |
88 | | - 'caption', |
89 | | - ) |
90 | | - ); |
91 | | - |
92 | | - /* |
93 | | - * Enable support for Post Formats. |
94 | | - * |
95 | | - * See: https://codex.wordpress.org/Post_Formats |
96 | | - */ |
97 | | - add_theme_support( |
98 | | - 'post-formats', |
99 | | - array( |
100 | | - 'aside', |
101 | | - 'image', |
102 | | - 'video', |
103 | | - 'quote', |
104 | | - 'link', |
105 | | - 'gallery', |
106 | | - 'audio', |
107 | | - ) |
108 | | - ); |
109 | | - |
110 | | - add_theme_support( 'menus' ); |
111 | | - } |
112 | | - |
113 | | - /** This Would return 'foo bar!'. |
114 | | - * |
115 | | - * @param string $text being 'foo', then returned 'foo bar!'. |
116 | | - */ |
117 | | - public function myfoo( $text ) { |
118 | | - $text .= ' bar!'; |
119 | | - return $text; |
120 | | - } |
121 | | - |
122 | | - /** This is where you can add your own functions to twig. |
123 | | - * |
124 | | - * @param string $twig get extension. |
125 | | - */ |
126 | | - public function add_to_twig( $twig ) { |
127 | | - $twig->addExtension( new Twig\Extension\StringLoaderExtension() ); |
128 | | - $twig->addFilter( new Twig\TwigFilter( 'myfoo', array( $this, 'myfoo' ) ) ); |
129 | | - return $twig; |
130 | | - } |
131 | | - |
132 | | -} |
133 | | - |
134 | 17 | new StarterSite(); |
0 commit comments