Skip to content

Commit

Permalink
Add compatibility with Timber v2
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Nov 17, 2023
1 parent 4e77d3e commit 7037607
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion lib/Timmy.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public static function init() {
add_action( 'after_setup_theme', [ $self, 'after_setup_theme' ] );

// Add filters and functions to integrate Timmy into Timber and Twig.
add_filter( 'timber/twig', [ $self, 'filter_twig' ] );
// add_filter( 'timber/twig', [ $self, 'filter_twig' ] );
add_filter( 'timber/twig/functions', [ $self, 'add_twig_functions' ] );
add_filter( 'timber/twig/filters', [ $self, 'add_twig_filters' ] );

add_filter( 'timmy/resize/ignore', array( __CLASS__, 'ignore_unallowed_files' ), 10, 2 );
}
Expand Down Expand Up @@ -167,6 +169,56 @@ public static function get_image( $attachment, $size ) {
return $image;
}

public function add_twig_functions( $functions ) {
$functions = array_merge( $functions, [
'get_timmy_image' => [
'callable' => [ '\Timmy\Timmy', 'get_image' ],
],
'get_timber_image_responsive_acf' => [
'callable' => 'get_timber_image_responsive_acf',
],
'get_timber_image_alt' => [
'callable' => 'get_timber_image_alt',
],
'get_timber_image_caption' => [
'callable' => 'get_timber_image_caption',
],
'get_timber_image_description' => [
'callable' => 'get_timber_image_description',
],
] );

return $functions;
}

public function add_twig_filters( $filters ) {
$filters = array_merge( $filters, [
'get_timber_image' => [
'callable' => 'get_timber_image',
],
'get_timber_image_src' => [
'callable' => 'get_timber_image_src',
],
'get_timber_image_srcset' => [
'callable' => 'get_timber_image_srcset',
],
'get_timber_image_responsive' => [
'callable' => 'get_timber_image_responsive',
],
'get_timber_image_responsive_src' => [
'callable' => 'get_timber_image_responsive_src',
],
'get_timber_picture_responsive' => [
'callable' => 'get_timber_picture_responsive',
],
'lazy' => [
'callable' => 'make_timber_image_lazy',
],
] );

return $filters;
}

/**
* Set filters to use Timmy filters and functions in Twig.
*
Expand Down

0 comments on commit 7037607

Please sign in to comment.