Welcome Guest, Not a member yet? Register   Sign In
View layout with two successive includes


I am currently working on a project based on CI4 and have now reached the layout. For this I would like to use the flexible View Layout System from CI, but I think I just found an error.

I use the following code to build the layout in a view:
PHP Code:
<?= $this->extend('layouts/main'?>
<?= $this
<?= $this

The layout looks like this:

PHP Code:
<!DOCTYPE html>
html lang="en">

title><?= env('app.site.title'?> - <?= $this->data['title'?></title>

<body id="page-top">

<!-- Page Wrapper -->
<div id="wrapper">
    <?= $this->renderSection('sidebar'?>

    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">

        <!-- Main Content -->
        <div id="content">

            <?= $this->renderSection('topbar'?>

In the respective Includes I assemble the Sections.
PHP Code:
<?= $this->section('sidebar'?>
<!-- Sidebar -->
<!-- End of Sidebar -->
<?= $this->endSection() ?>

PHP Code:
<?= $this->section('topbar'?>
<!-- Topbar -->
<!-- End of Topbar -->
<?= $this->endSection() ?>

Now I have the problem that I only get the first include of both, but never both at the same time. Does anyone know this problem or have a solution for it?


This should be in the CI4 Support section. Hopefully one of the admins will move it for you.

(This post was last modified: 01-10-2020, 09:19 AM by InsiteFX.)

You can still use echo view in the layout

PHP Code:
<?= view('includes/topbar'?>
<?= view

Try that, that's how it  is done in the Myth/Auth layout.

Also if you look at the include it is placed between the section and endSection.

PHP Code:
<?= $this->extend('default'?>

<?= $this->section('content'?>
    <h1>Hello World!</h1>

    <?= $this->include('sidebar'?>
<?= $this
->endSection() ?>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB