-
-
Notifications
You must be signed in to change notification settings - Fork 513
Update Object Getter function names in Twig #2144
Copy link
Copy link
Closed
Labels
Description
In #2073 (comment), we discussed whether we should keep the Post, Term, … functions in Twig:
For the API in Twig, we still have Post, PostQuery, etc. For consistency, should we consider renaming these functions to get_post(), get_posts(), etc?
I think renaming and deprecating the old Twig functions is probably a good idea. Seeing "Use
Timber::get_posts()instead ofnew Timber\PostQuery()" and then a paragraph later seeing "You can also use PostQuery in Twig" is a little jarring, and it's one less thing for new users to have to remember.
This is about the following functions in Twig:
Lines 49 to 70 in ca43edc
| /** | |
| * Timber object functions. | |
| */ | |
| $twig->addFunction(new TwigFunction('Post', function( $post_id, $PostClass = 'Timber\Post' ) { | |
| return self::maybe_convert_array( $post_id, $PostClass ); | |
| } ) ); | |
| $twig->addFunction( new TwigFunction( 'PostQuery', function( $args ) { | |
| return new PostQuery( $args ); | |
| } ) ); | |
| $twig->addFunction(new TwigFunction('Image', function( $post_id, $ImageClass = 'Timber\Image' ) { | |
| return self::maybe_convert_array( $post_id, $ImageClass ); | |
| } ) ); | |
| $twig->addFunction(new TwigFunction('Term', array($this, 'handle_term_object'))); | |
| $twig->addFunction(new TwigFunction('User', function( $post_id, $UserClass = 'Timber\User' ) { | |
| return self::maybe_convert_array( $post_id, $UserClass ); | |
| } ) ); | |
| $twig->addFunction( new TwigFunction( 'Attachment', function( $post_id, $AttachmentClass = 'Timber\Attachment' ) { | |
| return self::maybe_convert_array( $post_id, $AttachmentClass ); | |
| } ) ); |
This leaves us with the following todo:
- Deprecate
Post, addget_post() - Rename
PostQuerytoget_posts()(no need to deprecate, added for 2.x) - Deprecate
Term, addget_term() - Deprecate
User, addget_user() - Deprecate
Image, addget_image() - Rename
Attachmenttoget_attachment()(no need to deprecate, added for 2.x)
Reactions are currently unavailable