Hey there. I've stumbled upon a pretty weird situation while implementing a widgets support.
So the setup is as basic as this: I've created a blank new project and added as per now, 2 namespaces:
'Library' => __DIR__ . '/../app/libraries/',
'Widget' => __DIR__ . '/../app/widgets/',
Then, I've created the widget manager which loads the requested widget.
<?php
namespace Library;
class WidgetManager {
public static function load($widgetNamespace, $params = array()) {
$class = '\\Widget\\' . $widgetNamespace;
return new $class($params);
}
}
After that, I had to register the custom Volt function in my services.php
$compiler = $volt->getCompiler();
$compiler->addFunction('render_widget', function($args){
return '\\Library\\WidgetManager::load(' . $args . ')->getContent()';
});
Then I've created a really simple widget, to test it out:
<?php
namespace Widget\Frontend;
class Demo extends \Phalcon\DI\Injectable {
public function getContent() {
$this->view->start();
$this->view->render('widgets', 'Frontend/Demo');
$this->view->finish();
print $this->view->getContent();
}
}
Calling the widget as it is:
{% extends 'layouts/frontend.volt' %}
{% block content %}
{{ render_widget('Frontend\Demo') }}
{% endblock %}
worked fine at first. But, once I added my HTML code to my layout, calling my widget causes a recursion of its output. I've tried to delete the cached templates, I've enabled compileAlways as well. I call my widget once only in my index.volt template which extends my layout.
I really have no idea what could cause the recursion, since it was working just fine. Any kind of help/advice would be really appriciated.