Home > database >  Can codeigniter4 separate file of View Layout?
Can codeigniter4 separate file of View Layout?

Time:09-28

Here is my project example.

File : Header.php

<?= $this->extend('Default') ?>

<?= $this->section('content') ?>
  <!-- Left Sidebar -->
  <?= $this->include('Partials/Sidebar') ?>

  <!-- Main Container -->
  <div >

File : Footer.php

    <?= $this->include('Partials/Copyright') ?>
  </div>
  
  <?= $this->include('Partials/ToggleNavbar') ?>
  <script>
  </script>
<?= $this->endSection() ?>

Then put it together, it show only element in Footer.php .

<?= $this->include('Components/Header') ?>
<a>Hello world</a>
<?= $this->include('Components/Footer') ?>

CodePudding user response:

Fixed by put endSection in Header file, like this.

( It happened by guessing. I really appreciate it if there is someone can explain this )

File : Header.php

<?= $this->extend('Default') ?>

<?= $this->section('content') ?>
  <!-- Left Sidebar -->
  <?= $this->include('Partials/Sidebar') ?>

  <!-- Main Container -->
  <div >
<?= $this->endSection() ?> <!-- move to here -->

File : Footer.php

    <?= $this->include('Partials/Copyright') ?>
  </div>
  
  <?= $this->include('Partials/ToggleNavbar') ?>
  <script>
  </script>
<!-- deleted -->
  • Related