eXpect
eXpect

Reputation: 13

Can codeigniter4 separate file of View Layout?

Here is my project example.

File : Header.php

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

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

  <!-- Main Container -->
  <div class="main-container">

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') ?>

Upvotes: 0

Views: 98

Answers (1)

eXpect
eXpect

Reputation: 13

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 class="main-container">
<?= $this->endSection() ?> <!-- move to here -->

File : Footer.php

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

Upvotes: 1

Related Questions