Timber\Theme
Need to display info about your theme? Well you've come to the right place. By default info on the current theme comes for free with what's fetched by Timber::context()
in which case you can access it your theme like so:
PHP
<?php
$context = Timber::context();
Timber::render('index.twig', $context);
?>
Twig
<script src="{{ theme.link }}/static/js/all.js"></script>
HTML
<script src="https://example.org/wp-content/themes/my-theme/static/js/all.js"></script>
Overview #
This class extends Timber\Core
This class implements JsonSerializable
Properties #
Name | Type | Description |
---|---|---|
$name | string | the human-friendly name of the theme (ex: My Timber Starter Theme ) |
$parent | \Timber\Theme | the Timber\Theme object for the parent theme |
$parent_slug | string | the slug of the parent theme (ex: _s ) |
$slug | string | the slug of the theme (ex: my-timber-theme ) |
$uri | string | Retrieves template directory URI for the active (parent) theme. (ex: https://example.org/wp-content/themes/my-timber-theme ). |
$version | string | the version of the theme (ex: 1.2.3 ) |
Methods #
Name | Return Type | Summary/Returns |
---|---|---|
__call() | mixed | Magic method dispatcher for meta fields, for convenience in Twig views. Returns: The value of the meta field named $field if truthy, false otherwise. |
__construct() | Constructs a new Timber\Theme object. | |
display() | false or string | Gets a theme header, formatted and translated for display. |
get() | false or string | Gets a raw, unformatted theme header. Returns: String on success, false on failure. |
link() | string | Returns: Retrieves template directory URI for the active (child) theme. (ex: https://example.org/wp-content/themes/my-timber-theme ). |
path() | string | Returns: The relative path to the theme (ex: /wp-content/themes/my-timber-theme ). |
theme_mod() | string | |
theme_mods() | array |
Class Methods #
__call() #
Magic method dispatcher for meta fields, for convenience in Twig views.
Called when explicitly invoking non-existent methods on a Core object. This method is not meant to be called directly.
link https://secure.php.net/manual/en/language.oop5.overloading.php#object.call
__call( string $field, array $arguments )
Returns: mixed
The value of the meta field named $field
if truthy, false
otherwise.
This method is inherited from \Timber\Core
.
Name | Type | Description |
---|---|---|
$field | string | The name of the method being called. |
$arguments | array | Enumerated array containing the parameters passed to the function. Not used. |
PHP
$post = Timber\Post::get( get_the_ID() );
update_post_meta( $post->id, 'favorite_zep4_track', 'Black Dog' );
Timber::render( 'rock-n-roll.twig', array( 'post' => $post ) );
Twig
{# Since this method does not exist explicitly on the Post class,
it will dynamically dispatch the magic __call() method with an argument
of "favorite_zep4_track" #}
<span>Favorite <i>Zeppelin IV</i> Track: {{ post.favorite_zep4_track() }}</span>
__construct() #
Constructs a new Timber\Theme
object.
The Timber\Theme
object of the current theme comes in the default Timber::context()
call. You can access this in your twig template via {{ site.theme }}
.
__construct( string $slug = null )
Name | Type | Description |
---|---|---|
$slug | string |
PHP
<?php
$theme = new Timber\Theme("my-timber-theme");
$context['theme_stuff'] = $theme;
Timber::render('single.twig', $context);
Twig
We are currently using the {{ theme_stuff.name }} theme.
HTML
We are currently using the My Theme theme.
display() #
Gets a theme header, formatted and translated for display.
see WP_Theme::display()
display( string $header )
Returns: false|string
Name | Type | Description |
---|---|---|
$header | string | Name of the theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
Twig
{{ theme.display('Description') }}
get() #
Gets a raw, unformatted theme header.
see WP_Theme::get()
get( string $header )
Returns: false|string
String on success, false on failure.
Name | Type | Description |
---|---|---|
$header | string | Name of the theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
Twig
{{ theme.get('Version') }}
link() #
Returns: string
Retrieves template directory URI for the active (child) theme. (ex: https://example.org/wp-content/themes/my-timber-theme
).
path() #
Returns: string
The relative path to the theme (ex: /wp-content/themes/my-timber-theme
).
theme_mod() #
theme_mod( string $name, bool $default = false )
Returns: string
Name | Type | Description |
---|---|---|
$name | string | |
$default | bool |
theme_mods() #
Returns: array