renderSection() use in views file - deesoft service

renderSection() use in views file

Deepak Tailor Image
Deepak Tailor - Oct 02 2020
renderSection() use in views file

CodeIgniter supports a simple, yet very flexible, layout system that makes it simple to use one or more base page layouts across your application. There are many options given for using the layouts in the view file in codeigniter 4.

1. renderSection()

2. Extend()

3. included()

How to use renderSection() function

We use the render section function to show a section in our view file. Like –

$this->renderSection(‘section_name’);
$this->renderSection(‘navbar_section’);
How to use section() & endsection() function

With the section function, we set up a view section, then we set this set section to any file. Like –

<!-- navbar section set -->
<?= $this->section('navbar_section') ?>
    <h1>navbar section</h1>
<?= $this->endSection() ?>
<!-- navbar section set -->

<!-- menu list section set -->
<?= $this->section('menulist') ?>
    <h1>menu 1</h1>
    <h1>menu 2</h1>
    <h1>menu 3</h1>
    <h1>menu 4</h1>
<?= $this->endSection() ?>
<!-- menu list section set -->

<?= $this->include('admin/navbar'); ?>
<?= $this->renderSection('navbar_section'); ?>
<?= $this->renderSection('menulist'); ?>
How to use extends() and include() function

With the Extend function, we use a template to include our view file. And we also include to include the template. We use the Extend function in the header.

<?= $this->extend('admin/header'); ?>
<?= $this->include('admin/navbar'); ?>
Deepak Tailor Image
Deepak Tailor

My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
----
You can contact him at deepaktailor10@yahoo.in