diff --git a/guide/en/README.md b/guide/en/README.md index a97f3216..2ad14289 100644 --- a/guide/en/README.md +++ b/guide/en/README.md @@ -58,13 +58,11 @@ Views - ----- * [Views](views/view.md) - -* [Widgets](views/widget.md) - -* [Assets](views/asset.md) - -* [Working with client scripts](views/client-scripts.md) - -* [Theming](views/theming.md) - * [Template engines](views/template-engines.md) - * [View injections](views/view-injections.md) + - +* [Scripts, styles and metatags](views/script-style-meta.md) +* [Assets](views/asset.md) - +* [Widgets](views/widget.md) - Working with databases +- ---------------------- diff --git a/guide/en/views/asset.md b/guide/en/views/asset.md new file mode 100644 index 00000000..d8487ad8 --- /dev/null +++ b/guide/en/views/asset.md @@ -0,0 +1,5 @@ +# Assets + +> [!NOTE] +> [← Scripts, styles and metatags](script-style-meta.md) | +> [Widgets →](widget.md) diff --git a/guide/en/views/script-style-meta.md b/guide/en/views/script-style-meta.md new file mode 100644 index 00000000..7fa07932 --- /dev/null +++ b/guide/en/views/script-style-meta.md @@ -0,0 +1,5 @@ +# Scripts, styles and metatags + +> [!NOTE] +> [← View injections](view-injections.md) | +> [Assets →](asset.md) diff --git a/guide/en/views/template-engines.md b/guide/en/views/template-engines.md new file mode 100644 index 00000000..b97d2362 --- /dev/null +++ b/guide/en/views/template-engines.md @@ -0,0 +1,69 @@ +# Template engines + +Yii views support multiple template engines as well as custom engines. By default, Yii uses the PHP engine. +Additionally, [Twig](https://twig.symfony.com/) is available. + +## PHP + +PHP engine is available by default. The following is the basic template syntax: + +```php + + +Posts: + +
+ +
Title: getTitle()) ?>
+
Description: getDescription()) ?>
+ +
+``` + +At the very top of the template, you can define "uses" for classes to use and declare the type of variables +so the IDE understands them. The rest is the PHP code. + +> [!WARNING] +> ` `Html::encode()`. + +If you need a sub-view, you can use it like this: + +```php + + +Title + +render('blog/posts', ['posts' => $posts]) ?> +``` + +### See also + +- [yiisoft/view docs](https://github.com/yiisoft/view/blob/master/docs/guide/en/README.md). +- + +## Twig + +To use Twig, you need to install the [yiisoft/yii-twig](https://github.com/yiisoft/yii-twig). + + +> [!NOTE] +> [← Views](view.md) | +> [View injections →](view-injections.md) diff --git a/guide/en/views/view-injections.md b/guide/en/views/view-injections.md index fec00be8..89c7c808 100644 --- a/guide/en/views/view-injections.md +++ b/guide/en/views/view-injections.md @@ -1,9 +1,16 @@ # View injections The view injections are designed to provide a standardized way to pass parameters to the common layer -of views in an application. Implementing this interface allows developers to manage the data that will be available +of views in an application. It allows developers to manage the data that will be available across various views, ensuring flexibility and reusability of code. +The view injections could be used if you require `yiisoft/yii-view-renderer` package: + + +```sh +composer require yiisoft/yii-view-renderer +``` + ## Configuration In config `params.php`: @@ -101,3 +108,7 @@ Add your new injection to `params.php` under specific layout name. In the follow ], ], ``` + +> [!NOTE] +> [← Template engines](template-engines.md) | +> [Scripts, styles and metatags →](script-style-meta.md) diff --git a/guide/en/views/view.md b/guide/en/views/view.md new file mode 100644 index 00000000..8e0c344c --- /dev/null +++ b/guide/en/views/view.md @@ -0,0 +1,55 @@ +# Views + +Yii3 views could be used by requiring the `yiisoft/view` package: + +```sh +composer require yiisoft/view +``` + +The package provides template rendering abstraction supporting layout-view-subview hierarchy, custom renderers +with PHP-based as default, and more. + +Usage is the following: + +```php +``` + +If you're building a web application, you should require the `yiisoft/yii-view-renderer` package as well: + +```sh +composer require yiisoft/yii-view-renderer +``` + +It provides some extra web-specific functionality and adds compatibility with PSR-7 interfaces and could be used like +the following: + +```php +viewRenderer->render(__DIR__ . '/template', [ + 'name' => 'Sergei', + 'surname' => 'Predvoditelev', + ]); + } +} +``` + +In both cases a template file should be supplied. The template syntax depends on the template engine used. + +> [!NOTE] +> [Template engines →](template-engines.md) diff --git a/guide/en/views/widget.md b/guide/en/views/widget.md new file mode 100644 index 00000000..af3e39e9 --- /dev/null +++ b/guide/en/views/widget.md @@ -0,0 +1,5 @@ +# Widgets + + +> [!NOTE] +> [← Assets](asset.md)