Extending Timber

I’m using Timber for the first time, and I’m finding it hard to convert my pure PHP thinking to this templating model.

What I’m confused about at the moment is using a date which is an input field, not the post date.

So I’ve got a repeater field from ACF. It has three sub-fields: release_date, document_file, and document_title. My release date format is YYYY-MM-DD.

As you might have guessed, this repeater field is output as a list of PDFs.

So far so good, but then I want some advanced functionality – namely, to have the PDFs display by release_date by default. I also want to be able to filter by the year, i.e. – if you click “2015”, it would only show the documents from that year.

I know exactly how I would do this in straight WordPress, but I’m pretty confused as to how to do it in Timber. I’ve been trying to do it using a custom filter, but I have a feeling what I actually want is a custom class?

In addition, when I installed Timber it didn’t come with the starter theme, so I did a search and downloaded one from GitHub. I’ve got a feeling this is a legacy version though, because the file structure and syntax doesn’t seem to match the documentation.

Downloaded from here: https://github.com/timber/starter-theme

But for example this code in the starter theme functions.php:

function add_to_twig( $twig ) {
/* this is where you can add your own functions to twig */
$twig->addExtension( new Twig_Extension_StringLoader() );
$twig->addFilter('split_date', new Twig_SimpleFilter('split_date', array($this, 'split_date')));
return $twig;

}

Doesn’t quite match the syntax in https://github.com/timber/timber/wiki/Extending-Timber under “Adding to Twig”.

Read more here: Extending Timber

Leave a Reply

Your email address will not be published. Required fields are marked *