Welcome Guest, Not a member yet? Register   Sign In
Ci4 how to check if section exist with renderSection
#1

i need something like this:
PHP Code:
if ( isset ( $this->renderSection('content')) {
$this->renderSection('content');
}else{
$this->renderSection('default');
}

How can i check if section are declared in view
Reply
#2

You do not need to perform such a check by yourself.

In your layout file:


PHP Code:
<?= $this->renderSection('content'?>

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


In a view  that uses 'content':


PHP Code:
<?= $this->section("content"?>
// the content 
// simply ignore default
<?= $this->endSection() ?>


And in a view  that uses 'default':


PHP Code:
<?= $this->section("default"?>
// default
// simply ignore 'content
<?= $this->endSection() ?>

CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5)

Reply
#3

If you have 2 different sections then you should have 2 different templates for each one.

Template1 - view1 // content
Template2 - view2 // default
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