codeigniter4可以分离视图布局文件吗?

lmyy7pcs  于 2022-12-16  发布在  其他
关注(0)|答案(1)|浏览(97)

这是我的项目示例。
文件:首页

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

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

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

文件:首页

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

然后把它放在一起,它只显示元素在Footer.php .

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

qyyhg6bp1#

通过在头文件中放置endSection进行修复,如下所示。
(猜测而已,如果有人能解释的话,我真的很感激)
文件:首页

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

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

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

文件:首页

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

相关问题