Templates
Templates are user-defined, dynamic, reusable snippets of HTML. The publisher provides an API to every piece of data related to your podcast. Using templates, you can display every detail in every layout you like.
Twig is used to make templates dynamic. Printing a variable in Twig looks like this:
You can iterate over a list of items:
These are the basics. You can refer to the Twig Documentation for all available options.
Creating Twig Templates — For Podlove Publisher Users
To create a template, go to Podlove → Templates
and click "Add New".
The ID is used to reference the template from your episodes or pages. Choose a descriptive name. The fun starts below. The HTML Template is a freeform textfield. Write HTML/Twig there. All template variables and WordPress shortcodes are available. Click save when you are done.
Go to any post, page or episode and paste the template shortcode. It should look like this:
[podlove-template template="episode"]
Save and view the edited page. You should see the contents of your template. You can now go back to the template and edit until you like the results.
Episode Templates
Templates which are used in episodes are special. In episodes, an additional variable is available: episode
. It contains the current episode object.
For example, you could build your own download list:
Shortcode Options
To make template modular and reusable, you can pass options to the template shortcode. They are then available under the option
accessor. So a template embedded using [podlove-template template="episode" language="en"]
will have access to the variable {{ option.language }}
.
To set option defaults. Here is an example:
Subtemplates
If you are looking for a way to reuse template parts or want to split up complex templates, subtemplates are the solution. They allow to embed templates in templates while keeping the scope of one local variable. All global variables are available as usual.
An example:
The template file-link
contains the markup to render the link to a file.
Now this template can be used in another template. All variables from the parent template are available in the child template.
Macros
Twig allows you to create macros to put often used HTML idioms into reusable elements to not repeat yourself. To be able to use them in multiple templates, they are best saved in a separate template. You might call it "mymacros":
To use them in another template, you need to import the macros before using them:
Filters
Twig filters can be used to filter the list of episodes. For example, this filter selects only the episodes from the year 2024:
Creating PHP Templates — For Theme Developers
Available from Podlove Publisher version 2.3
You have access to the complete Podlove Publisher template system from PHP, which is ideal for creating themes.
The template variables and API is identical to the one provided by Twig. Just the syntax is different.
is equivalent to
<ul>
<?php foreach (\Podlove\get_podcast()->episodes() as $episode): ?>
<li><?php echo $episode->title() ?></li>
<?php endforeach ?>
</ul>
API Entry Points
There are currently 4 entry points to the API: through the podcast, episode, network or Flattr.
Podcast
<?php
/**
* Get Podlove podcast template object.
*
* @param int $blog_id Optional. Blog ID. Defaults to global $blog_id.
* @return \Podlove\Template\Podcast
*/
function \Podlove\get_podcast($blog_id = null);
// example
$podcast = \Podlove\get_podcast();
echo $podcast->title();
?>
Episode
<?php
/**
* Get Podlove episode template object.
*
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
* @return \Podlove\Template\Episode
*/
function \Podlove\get_episode($id = null);
// example
$episode = \Podlove\get_episode();
echo $episode->player(['context' => 'episode']);
?>
Network
<?php
/**
* Get Podlove network template object.
*
* Only available in WordPress Multisite environments.
*
* @return \Podlove\Modules\Networks\Template\Network
*/
function \Podlove\get_network();
// example
$network_lists = \Podlove\get_network()->lists();
?>
Flattr
<?php
/**
* Get Podlove Flattr template object.
*
* Requires "Flattr" module.
*
* @return \Podlove\Modules\Flattr\Template\Flattr
*/
function \Podlove\get_flattr();
// example
echo \Podlove\get_flattr([
'url' => 'http://wordpress.org/extend/plugins/podlove-podcasting-plugin-for-wordpress/',
'user' => 'ericteubert'
]);
?>
Hint: Short syntax for PHP 5.6+
If you develop a theme for PHP 5.6+ environments, you may want to use function importing for a nicer syntax, like that:
<?php
// once at the beginning of each file, ONLY PHP 5.6+
use function \Podlove\get_episode;
use function \Podlove\get_podcast;
echo get_podcast()->title();
?>