I'm using Timber for the first time, and I find that it is 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 making it on Timber. I've been trying to do it using a custom filter, but I have felt 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".
filteris a bit different but still correct. Usingarray($this, 'split_date)` is equal telling totwig: Add a new filtersplit_dateand allocate it the function based in$thisclass. The example in the documentation is using global functions instead of class methods - DarkBeesplit_date) and use day, year and month separately. - rickibarnes<a href="route/to/file?year={{ release_date | date('Y') }}">{{ release_date | date('Y-m-d') }}</a>- DarkBeefooter.twigfor the first time. That is exactly what I'm looking for, cheers. It is perfectly nice and simple, though I'm still a little confused by the documentation. I didn't see that syntax in the examples anywhere. - rickibarnes