Welcome Guest, Not a member yet? Register   Sign In
How to render section in nested view?
#1

I have this layout:

PHP Code:
<!DOCTYPE html>
<
html>

<
head>
  <meta charset="utf-8">
</
head>

<
body>
  <div class="wrapper">

    <!-- Navbar -->
    <?= $this->include('App\Views\Backend\layout\header'?>
    <!-- /.navbar -->

      <!-- Main content -->
      <section class="content">
        <div class="container-fluid">
          <?= $this->renderSection('content'?>
        </div>
      </section>
      <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

  </div>
  <!-- ./wrapper -->

  <!-- REQUIRED SCRIPTS -->

  <!-- jQuery -->
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
 
  <!-- Render section boilerplate js -->
  <?= $this->renderSection('js'?>
</body>

</html> 

In my View I have this implementation:

PHP Code:
<?= $this->include('App\Views\Backend\load\datatables'?>
<?= $this
->include('App\Views\Backend\load\dropzone'?>

<!-- Extend from layout index -->
<?= $this->extend('App\Views\Backend\layout\index'?>

<!-- Section content -->
<?= $this->section('content'?>

<?= $this->include('App\Views\Backend\Media\Dropzone\index'?>
<?= $this
->include('App\Views\Backend\Media\toolbar'?>
<?= $this
->include('App\Views\Backend\Media\list'?>

<?= $this->endSection() ?>

<?= $this->section('js'?>
<?= $this
->include('App\Views\Backend\Media\Dropzone\config'?>
<?= $this
->endSection() ?>

as you can see I call layout\index to include the View in the body content. Now the problem's that inside Media\list I have a section called js:

PHP Code:
<?= $this->section('js'?>
<script>
... 

and this raise an error:

PHP Code:
View themesno current section 

[Image: t8DhOD7.png]urrent section current section
Reply
#2

Migrate to ci4
Enlightenment  Is  Freedom
Reply
#3

(04-27-2021, 09:14 AM)paliz Wrote: Migrate to ci4

well.. I'm using CI4  Confused
Reply
#4

I think you should use $this->include() instead of view() in your template.
Reply
#5

(04-28-2021, 10:42 PM)iRedds Wrote: I think you should use $this->include() instead of view() in your template.

I've also tried with include but same result
Reply
#6

Oh really. I missed it.
If I understand the code correctly, in the current implementation you cannot use nested sections.
Reply
#7

(04-29-2021, 01:09 AM)iRedds Wrote: Oh really. I missed it.
If I understand the code correctly, in the current implementation you cannot use nested sections.

mmm so I have to create one js file that handle all the logic and then include it in the main view?
Reply
#8

I added a PR to solve this problem. https://github.com/codeigniter4/CodeIgniter4/pull/4622
Reply
#9

(04-29-2021, 02:05 AM)sfarzoso Wrote: mmm so I have to create one js file that handle all the logic and then include it in the main view?

If this solution suits you, then I cannot stop you =)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB