We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Existing Content not put in template

Hello,

if I put some html into the view object before render, I don't see it in the final render any more, Why?

tpl1.volt

<div class="container-debug">
    <strong>{{ id }}</strong><br>
    {{ content() }}
</div>

ContentModel.php

class ContentModel extends Model {
            public function processContainer($idNavi)
                {
                        $view = $this->getDI()->getView();

                        // some code

                        $view->setContent($html);

                        $view->start();
                        $view->render('mytpl', 'tpl1');
                        $view->finish();
                        $return_html = $view->getContent();

                        return $return_html;
                }
}

Since you're rendering manually, try this:

            public function processContainer($idNavi)
                {
                        $view = $this->getDI()->getView();
                        // some code
                        $html = 'test me content';
                        $return_html = $view->getRender('mytpl', 'tpl1', ['content'=>$html]);
                        return $return_html;
                }


4.8k

$return_html is empty, getRender returns nothing.

Try this:

                        $view = clone $this->getDI()->getView();
                        $view->->setRenderLevel(View::LEVEL_NO_RENDER);
                        // some code
                        $html = 'test me content';
                        $return_html = $view->getRender('mytpl', 'tpl1', ['content'=>$html]);
                        return $return_html;


4.8k

$return_html is still empty I call ContentModel::processContainer like this from the controller:

$cm = new ContentModel();
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$html = $cm->processContainer($id);

Hmm... does the view get rendered in regular context? (like https://app.dev/mytpl/tpl1)



4.8k
$this->view->start();
$this->view->getRender('flow', 'test', ['content' => 'teststring']);
$this->view->finish();
$html = $this->view->getContent();

I have in $html the complete html for the webpage views/index.volt including views/flow/test.volt, but without teststring, which should be in test.volt