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:: - extend('Blog\Views\default') ?> + 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 @@ +setVar('title', 'Homepage')->extend('default') ?> + +setVar('hideNavbar', true)->section('content') ?> +

Items List

+ + setData(['item' => $item])->include('item_card') ?> + +endSection() ?> \ No newline at end of file diff --git a/user_guide_src/source/outgoing/views.rst b/user_guide_src/source/outgoing/views.rst index c08a3e61f97f..7d284cb1772e 100644 --- a/user_guide_src/source/outgoing/views.rst +++ b/user_guide_src/source/outgoing/views.rst @@ -91,7 +91,7 @@ When doing so you will need to include the directory name loading the view. Exam Namespaced Views ================ -You can store views under a **View** directory that is namespaced, and load that view as if it was namespaced. While +You can store views under a **Views** directory that is namespaced, and load that view as if it was namespaced. While PHP does not support loading non-class files from a namespace, CodeIgniter provides this feature to make it possible to package your views together in a module-like fashion for easy re-use or distribution. @@ -99,7 +99,8 @@ If you have **example/blog** directory that has a PSR-4 mapping set up in the :d under the namespace ``Example\Blog``, you could retrieve view files as if they were namespaced also. Following this -example, you could load the **blog_view.php** file from **example/blog/Views** by prepending the namespace to the view name: +example, you could load the **blog_view.php** file from **example/blog/Views** by prepending the namespace to the view name +(specifying the end directory ``Views`` as an ``Example\Blog\Views\`` not required): .. literalinclude:: views/005.php diff --git a/user_guide_src/source/outgoing/views/005.php b/user_guide_src/source/outgoing/views/005.php index e9ad6a75d7b5..45d762f74dc8 100644 --- a/user_guide_src/source/outgoing/views/005.php +++ b/user_guide_src/source/outgoing/views/005.php @@ -1,3 +1,3 @@