-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Timber (as a composer library) #14
Comments
|
Our experience of Timber on Wilton Park has left me uncertain as to whether or not it's a good thing. In theory, it still delivers real benefits, but the way it's structured seems particularly unfriendly to testing. Particular issues I encountered were:
It might be that we can deal with the first couple of issues via Kahlan once we're a bit more familiar with it, and the third could potentially be remedied via team convention/code review. But I feel like we need more experience of it before we can really know if it's the right tool. In particular, I think we need to be sure it doesn't hinder our ability to write testable code. |
If we do end up using Timber, we should use a linter for the twig templates, e.g. https://github.com/sserbin/twig-linter |
I think the release of Timber 2.0 might help with getting the logic into testable classes. e.g. there's a Any of the classes that are being hooked in like that could extend a parent class that automates that hooking in process maybe? We could make that parent class part of Iguana if needs be. |
You can set your own locations for your twig files with: |
For the svg inline, there is https://github.com/manuelodelain/svg-twig-extension OR if your SVG lies in a folder called assets/icons/ in the main folder of your theme, you add that folder to the list: functions.php
You can then do
If you have only one file to include, it’s probably overkill to make Timber look in another directory. You could also use file_get_contents() and get_template_directory().
OR simply rename the .svg as .twig (it's text right?) and include it. |
I'm not sure what was the problem, because you can actually do that:
But honestly I would prefer escaping one by one e.g.
considering that Timber has
|
could you please make an example of this?
Half true: you can declare the menus on the global context,
Half true again: you can declare twig files separated from a specific php, See: https://timber.github.io/docs/guides/extending-timber/#an-example-that-extends-timberpost These can get pretty complex. And that's the beauty. The complexity lives inside the context of the object, but very simple when it comes to your templates. In that case, I think we could easily use Kahlan too |
e.g.
Looking at the documentation for declaring menus on the global context (https://timber.github.io/docs/guides/menus/#setting-up-a-menu-globally), it looks like this still requires a
I do like the look of the way you can extend the post object. That's something I've wanted to do with standard I think my main concern on this point was where there are e.g. parameters in the query string that should be used to determine what post query is run. The Timber docs don't really offer any pointers as how you should deal with a situation like that, so the obvious solution is to put all that logic into the .php file that lives with the .twig template (which as a result won't be testable, and possibly hard to maintain). I guess maybe a couple of alternatives in a case like that might be to:
|
I think we should consider to try and set up a new starter theme with this logic, and see how it works. I don't like the second alternative because hooking on |
Advantage: clean separation of templates and other code
Disadvantage: new syntax to learn
https://timber.github.io/docs/
The text was updated successfully, but these errors were encountered: