rendering partials with View::instance()

46 views
Skip to first unread message

Martin Kirk

unread,
Jun 16, 2022, 8:13:58 AM6/16/22
to Fat-Free Framework
Hi,

F3 newbie here, trying to find out the best way to render partials.  I'm not using F3's templating engine but instead using PHP templates with F3's View::instance()->render() method.

I have a controller with the following method:

public function dashboard($f3)
{
    $body = View::instance()->render('app/views/dashboard.php');
    $f3->set('body', $body);
    $this->f3->set('ESCAPE', false);
     echo View::instance()->render('app/views/core_master.php');
     $this->f3->set('ESCAPE', true);
}

The core_master.php template has a single placeholder for $body, which I want to fill with the partial.

If I don't use the f3->set('ESCAPE', true) directive then my partial has html entities encoded and so doesn't render properly.

Is there another approach that doesn't require me to set ESCAPE to false?

Thanks,
Martin.


ikkez

unread,
Jun 18, 2022, 2:49:57 AM6/18/22
to Fat-Free Framework
Rename files to .html

In your master.html template simply add:

<div>
  <?php echo $this->render('dashboard.html');  ?>
</div>

or with dynamic variable:   <?php echo $this->render(Base::instance()->get('body')); ?>


escaping contents is described here ;) https://fatfreeframework.com/3.8/view#esc

Martin Kirk

unread,
Jun 20, 2022, 8:55:02 AM6/20/22
to Fat-Free Framework

Thanks Ikkez, I hadn't thought of calling $this->render() from within the master template, that achieves what I need.

I haven't renamed my templates to .html as you suggest, surely that would prevent me from using <?php echo ... ?> in my templates?
Reply all
Reply to author
Forward
0 new messages