diff --git a/user_guide_src/source/outgoing/view_cells.rst b/user_guide_src/source/outgoing/view_cells.rst index e01bdcd53343..efc27b11e320 100644 --- a/user_guide_src/source/outgoing/view_cells.rst +++ b/user_guide_src/source/outgoing/view_cells.rst @@ -119,7 +119,7 @@ You can also create a controlled cell via a built in command from the CLI. The c Using a Different View ====================== -You can specify a custom view name by setting the ``view`` property in the class. The view will be located like any view would be normally: +You can specify a custom view filepath by setting the ``view`` property in the class. The view will be located like any view would be normally: .. literalinclude:: view_cells/011.php @@ -145,16 +145,20 @@ If you need to perform additional logic for one or more properties you can use c .. important:: You can't set properties that are declared as private during cell initialization. + Call ``getDataProperty()``, ``getViewProperty()`` methods are not available - they are used for internal processes. Presentation Methods ==================== Sometimes you need to perform additional logic for the view, but you don't want to pass it as a parameter. You can implement a method that will be called from within the cell's view itself. This can help the readability of your views: +You may have noticed that not only method calls are allowed in the template: the entire Сell object with public properties is available. .. literalinclude:: view_cells/016.php .. literalinclude:: view_cells/017.php + + Performing Setup Logic ====================== diff --git a/user_guide_src/source/outgoing/view_cells/011.php b/user_guide_src/source/outgoing/view_cells/011.php index 75f37da190db..cddb2f7cc31e 100644 --- a/user_guide_src/source/outgoing/view_cells/011.php +++ b/user_guide_src/source/outgoing/view_cells/011.php @@ -9,5 +9,5 @@ class AlertMessageCell extends Cell public $type; public $message; - protected string $view = 'my/custom/view'; + protected string $view = APPPATH . 'Views/cells/alerts.php'; } diff --git a/user_guide_src/source/outgoing/view_layouts.rst b/user_guide_src/source/outgoing/view_layouts.rst index 6e6c672710fd..7173381342c0 100644 --- a/user_guide_src/source/outgoing/view_layouts.rst +++ b/user_guide_src/source/outgoing/view_layouts.rst @@ -64,7 +64,7 @@ The ``extend()`` method takes the name of any view file that you wish to use. Si be located just like a view. By default, it will look in the application's View directory, but will also scan other PSR-4 defined namespaces. You can include a namespace to locate the view in particular namespace View directory:: - = $this->extend('Blog\Views\default') ?> + = $this->extend('Blog\default') ?> All content within a view that extends a layout must be included within ``section($name)`` and ``endSection()`` method calls. Any content between these calls will be inserted into the layout wherever the ``renderSection($name)`` call that @@ -122,3 +122,15 @@ view to view. When using view layouts you must use ``$this->include()`` to inclu When calling the ``include()`` method, you can pass it all of the same options that can when rendering a normal view, including cache directives, etc. + +********************* +Assign Data to Layers +********************* + +You can pass additional variables to your templates, just like for ``view()``. If you don't use the ``saveData = false`` flag anywhere +in the templates, then the data will be inherited for each block. + +.. note:: When using a loop, passing new variables is required. + +.. literalinclude:: view_layouts/002.php + diff --git a/user_guide_src/source/outgoing/view_layouts/002.php b/user_guide_src/source/outgoing/view_layouts/002.php new file mode 100644 index 000000000000..f99a58dc4129 --- /dev/null +++ b/user_guide_src/source/outgoing/view_layouts/002.php @@ -0,0 +1,8 @@ += $this->setVar('title', 'Homepage')->extend('default') ?> + += $this->setVar('hideNavbar', true)->section('content') ?> +