Welcome Guest, Not a member yet? Register   Sign In
extend layout
#3

(This post was last modified: 11-11-2021, 07:37 AM by nemesis.)

I am sorry, I'll be more precisely with some examples. this is my view:
Code:
<?= $this->extend('default'); ?>

<?= $this->section('theBody') ?>
<b>This is my body, as I write in my view</b>
<?= $this->endSection() ?>
and this is my default.php, as suggest from user guide:
Code:
<!doctype html>
<html>
<head>
    <title>My Layout</title>
</head>
<body>
    <?= $this->renderSection('theTitle') ?>
    <?= $this->renderSection('theBody) ?>
</body>
</html>
since renderSection return nothing, how can I test if it's used by a view?

I've try to change system\View.php from
Code:
public function renderSection(string $sectionName){
  if (! isset($this->sections[$sectionName])) {
      return;
  }
  foreach ($this->sections[$sectionName] as $key => $contents) {
      echo $contents;
      unset($this->sections[$sectionName][$key]);
  }
}

to:
Code:
public function renderSection(string $sectionName){
  if (! isset($this->sections[$sectionName])) {
      return true;
  }
  foreach ($this->sections[$sectionName] as $key => $contents) {
      echo $contents;
      unset($this->sections[$sectionName][$key]);
  }
}

so that my layout become:
Code:
<!doctype html>
<html>
<head>
    <title>My Layout</title>
</head>
<body>
    <?php if ($this->renderSection('theTitle')): ?>
        <h1>default header</h1>
    <?php endif ?>
    <?php if ($this->renderSection('theBody)): ?>
        <p>default body</p>
    <?php endif ?>
</body>
</html>

this work fine but it isn't the right way! I will not change system source code... more over, it do a wrong render when I use multiple times (one inside another)...
Reply


Messages In This Thread
extend layout - by nemesis - 11-10-2021, 09:18 AM
RE: extend layout - by InsiteFX - 11-11-2021, 03:12 AM
RE: extend layout - by nemesis - 11-15-2021, 08:49 AM
RE: extend layout - by nemesis - 11-11-2021, 07:26 AM
RE: extend layout - by ikesela - 11-11-2021, 09:45 AM
RE: extend layout - by nemesis - 11-11-2021, 03:20 PM
RE: extend layout - by kenjis - 11-12-2021, 11:33 PM
RE: extend layout - by nemesis - 11-13-2021, 01:40 AM
RE: extend layout - by kenjis - 11-15-2021, 06:40 PM
RE: extend layout - by nemesis - 11-16-2021, 12:58 AM
RE: extend layout - by kenjis - 11-16-2021, 01:16 AM
RE: extend layout - by nemesis - 11-16-2021, 08:33 AM
RE: extend layout - by kenjis - 11-16-2021, 03:58 PM
RE: extend layout - by nemesis - 11-17-2021, 11:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB