-
-
Notifications
You must be signed in to change notification settings - Fork 513
Implement top-level image methods #2333
Description
Is your feature request related to a problem? Please describe.
When dealing with attachments in the new Posts API , instead of calling new Image() or new Attachment() directly, one would just call Timber::get_post(). This is a potential point of confusion, as in some cases it may not be obvious from looking at user code that we're actually getting an attachment:
<img src="{{ get_post( post.meta('my_img') ) }}">This is arguably more intuitive:
<img src="{{ get_image( post.meta('my_img') ) }}">
{# or #}
<img src="{{ get_attachment( post.meta('my_img') ) }}">Describe the solution you’d like
Two small additions to the API:
- Add
Timber::get_image()andTimber::get_attachment()as aliases toTimber::get_post() - Add corresponding
get_image()andget_attachment()Twig functions
The drawback here is that aliases are also potentially confusing, since it's possible you won't get an Attachment instance back from ::get_attachment(). But this is probably less likely than the inverse case, since you're unlikely to use ::get_attachment() in a situation where you don't already have an attachment ID. To cover out bases, in the docs we should say something like:
Alias for Timber::get_post(). Honors Class Maps and query params in exactly the same way. That means it's possible to get something other than an Attachment (such a plain Timber\Post object) back if you pass something other than an attachment ID. Intended to clarify your code when you already know you have an attachment ID.
Describe alternatives you’ve considered
Just using ::get_post() for everything. Potentially confusing.
Additional context
Discussion starts here: #2316 (review)