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

Hello,

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
->include('includes/topbar'?>
<?= $this
->include('includes/sidebar'?>


The layout looks like this:

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

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

<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'?>
        </div>
    </div>
</div>
</body>
</html> 

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?
Reply
#2

@elyday,

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

(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
('includes/sidebar'?>

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 )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB