diff --git a/README.md b/README.md index d1b889f..6ae434f 100644 --- a/README.md +++ b/README.md @@ -56,5 +56,11 @@ WPify Models, so we can access data easily and use them wherever we need. Links: [WPify Model](https://packagist.org/packages/wpify/model) +### 05 - WPify Templates -[Next step >>>](https://github.com/wpify/plugin-tutorial/tree/05-templates) +We want to be able to render templates easily, even in Twig. In this step, we are adding WPify Templates. + +Links: [WPify Templates](https://packagist.org/packages/wpify/templates) + + +[Next step >>>](https://github.com/wpify/plugin-tutorial/tree/06-assets-utils) diff --git a/bootstrap.php b/bootstrap.php index 54c9bbc..adc387f 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -19,6 +19,8 @@ use WpifyPluginTutorialDeps\DI\NotFoundException; use WpifyPluginTutorial\Plugin; use WpifyPluginTutorialDeps\Wpify\Model\Manager; +use WpifyPluginTutorialDeps\Wpify\Templates\TwigTemplates; +use WpifyPluginTutorialDeps\Wpify\Templates\WordPressTemplates; use function WpifyPluginTutorialDeps\DI\create; @@ -39,7 +41,13 @@ function wpifypt_container(): Container { if ( empty( $container ) ) { $containerBuilder = new ContainerBuilder(); $containerBuilder->addDefinitions( array( - Manager::class => create()->constructor( array() ) + WordPressTemplates::class => create()->constructor( array( + plugin_dir_path( __FILE__ ) . 'templates', + ) ), + TwigTemplates::class => create()->constructor( array( + plugin_dir_path( __FILE__ ) . 'templates', + ) ), + Manager::class => create()->constructor( array() ) ) ); $container = $containerBuilder->build(); } diff --git a/composer-deps.json b/composer-deps.json index e1bcfd7..0404001 100644 --- a/composer-deps.json +++ b/composer-deps.json @@ -3,6 +3,7 @@ "php": "^8.0", "php-di/php-di": "^7.0", "wpify/custom-fields": "^3.9", - "wpify/model": "^4.0" + "wpify/model": "^4.0", + "wpify/templates": "^3.0" } } diff --git a/src/Blocks/BookLinkBlock.php b/src/Blocks/BookLinkBlock.php index 3f6af9c..8759d91 100644 --- a/src/Blocks/BookLinkBlock.php +++ b/src/Blocks/BookLinkBlock.php @@ -5,6 +5,8 @@ use WpifyPluginTutorial\Managers\BlocksManager; use WpifyPluginTutorial\Repositories\BookRepository; use WpifyPluginTutorialDeps\Wpify\CustomFields\CustomFields; +use WpifyPluginTutorialDeps\Wpify\Templates\TwigTemplates; +use WpifyPluginTutorialDeps\Wpify\Templates\WordPressTemplates; class BookLinkBlock { const KEY = 'wpify/book-link'; @@ -12,6 +14,8 @@ class BookLinkBlock { public function __construct( CustomFields $custom_fields, private BookRepository $book_repository, + private WordPressTemplates $wp_template, +// private TwigTemplates $twig_template, ) { $custom_fields->create_gutenberg_block( array( 'name' => self::KEY, @@ -46,6 +50,7 @@ public function render( $block_attributes, $content ) { $block_attributes['isbn'] = $book->isbn; // return the string with the rendered block. - return '