Conversation
|
Ok, I did some more tinkering and added a public method that can be used from within php templates as well. Now, to add any extra context, you can use a php template file and let the // author.php
$context = array();
$context['author'] = new TimberUser( get_the_author_meta( 'ID' ) );
$context['title'] = 'Author Archives: ' . $context['author']->name();
TimberTemplateLoader::load_template( $context );Makes for quite elegant template loading! The API needs some thought - maybe this should be merged with |
|
Sorry, when I deleted the |
Makes it easier to add support for plugins that like to mess with the loop (eg. BuddyPress). This way you can add support for popular plugins by writing small plugins/extensions like this: https://github.com/slimndap/TimberBuddyPress No need to add any hacky code to you theme anymore!
* master: (52 commits) additional test for route; fixing some phpdoc pieces fixed issue with missing menu classes and test to ensure it doesn't happen again timber#288 allow 2nd argument of TimberPost::get_terms to be class investigated error reported by slimndap. Wrote test to cover so it doesn't happen again. Close timber#287 Correctly test date filter support for DateTime objects restored test to make sure undefined properties don't throw errors don't allow null things to be iterated over, force them to be empty arrays when null more deprecation notes, test for pagination in category updated change log added .name to all links in pagination numbers; updating version to 0.20.0 disable open_basedir test for coveralls remove open_basedir setting after test another tweak to openbasedir test tweak to openbasedir test more tests for children; resolved issue for getting the originating object's data only fetch travis badge for master verified timber#276 with additional tests. close timber#276 started some tests fixed issue with id timber#276 Added unit tests for page links ...
…o potentially spin it out into a sep. repo/project
…tch-1 * 'patch-1' of github.com:slimndap/timber: Add a filter to TimberPostGetter::get_posts
fix minor typos in theme template commments
My Timber-generated pages were failing HTML validation due to some improperly closed standalone tags. This changes those tags to the correct formatting. I left the close slash for backward compatibility with XHTML. There may be other tags, but these were the ones that quickly came to mind.
…ord-admin-notices * 'admin-notices' of github.com:andyford/timber: Use admin_url() in 'Timber not activated' message in case WP installed at custom path
* andyford-admin-notices: placing path inside of admin_url() function Use admin_url() in 'Timber not activated' message in case WP installed at custom path
* 'patch-1' of github.com:discern/timber: Update timber-helper.php
… the constant TimberLoader::AUTOLOAD_TEMPLATE is passed
…h overloading and the TimberLoader::AUTOLOAD_TEMPLATE constant
…al through overloading
…le method for issues with MenuTests
…ierarchy is not true
This way it's called every time the context is queried. Let the filter decide if it wants to cache its part of the context or not.
70748ea to
c316729
Compare
|
Hi @jarednova, We have left this one hanging for much too long now! I have rebased It's been a while, so here is a recap of what's included in this PR:
At the time, I made an opinionated started theme for Timber that relied heavily on the template autoloader. I didn't push it to GitHub then because I figured I'd wait for this to be merged into I used it to build a proof-of-concept Foundation theme based on Timber, which I'll also push some time this week. What are your thoughts about bringing this to Mike |
|
@jarednova is this door shut now? what triggered the close? |
|
That was not intentional. I cleaned-up some stale branches this AM, but this one says it's still open. Hmm...... |
|
Hi @jarednova, Accidental close again? Just finished another Timber site using the template loader (here) and still convinced that this is the way to go for theme development with Timber. The theme is mostly twig templates, as opposed to a mess of PHP files. I just added some more commits to this branch:
Do you have any plans of merging this into master? If so, I'll rebase again! Cheers, |
Now that the query is added to the context by default (#277), the WordPress template files often just repeat the same melody.. get context and render a twig file with pretty much the same name as the php template.
So I quickly put together this PR (which is a proof-of-concept for discussion), which adds a template loader to the default WP template loading that loads twig templates according to the same logic as the WP template hierarchy if no php template is found.
It checks what the query is for, and checks if an appropriate twig template exists in any of the Timber locations, exactly as the WP Template hierarchy does. If a twig template is found, it is rendered using
the default context (
Timber::get_context()).For example, if the query is for a single post of the
portfoliopost type, the following files will be looked for:child-theme/single-portfolio.phpparent-theme/single-portfolio.phpchild-theme/single.phpparent-theme/single.php..and then..
child-theme/views/single-portfolio.twigparent-theme/views/single-portfolio.twigchild-theme/views/single.twigparent-theme/views/single.twig...and then...
child-theme/index.php(NB!)parent-theme/index.phpchild-theme/views/index.twigparent-theme/views/index.twigAs a proof-of-concept, I have included a naked version of the starter theme in this PR, so you can see that the sites can actually run without template files :)
A few notes:
index.php, so the code in the PR checks theindex.phpin a hacky way: if{template}.twigis not found, it renders the foundindex.phpand sees if there is any output. If there is output, it will useindex.php. If there's no output, it will continue looking forindex.twig. (there is a filter to override this) We may have to think this through.get_index_templatefunction. If a timber template is found, it is rendered and the filter returnsfalse. WP will then simply not include a template file... unless a plugin has filteredtemplate_includeto use its own templates (WooCommerce? BuddyPress?). This is something test and perhaps find solution for...Let me know if you agree this is a valid strategy, then I'll work it out some more and write tests.