redrawControl() in component
Notice: This thread is very old.
- Eijliaan
- Member | 2
Hi,
I have this component
<?php
use Nette,
App\Model;
class Rating extends Nette\Application\UI\Control {
private $presenter;
private $context;
public function __construct($presenter, $context) {
parent::__construct($presenter, $context);
$this->presenter = $presenter;
$this->context = $context;
}
public function renderAdd() {
$this->template->rating = 'some rating...';
$this->template->setFile(dirname(__FILE__) . "/default.latte");
$this->template->render();
}
public function handleRate() {
if ($this->isAjax()) {
$this->template->rating = 'new rating...';
$this->presenter->redrawControl('rating');
}
}
}
?>
with this template
<a href="{link rate!}" class="ajax">Rate</a>
{snippet rating}
{$rating}
{/snippet}
called in main template like {control rating:add}
.
The problem is when I click on the link, the {snippet rating}
will not redraw itself (the response is {"state":[]}
). When snippet
is in component, it has ID like snippet-componentName-snippetName
,
instead of snippet--componentName-snippetName
(this way is it in
main templates, without componentName of course).
I have also tried to change handle to this
<?php
public function handleRate() {
if ($this->isAjax()) {
$this->template->rating = 'new rating...';
$this->redrawControl('rating');
$this->template->setFile(dirname(__FILE__) . "/default.latte");
$this->template->render();
}
}
?>
It returns a response at least (HTML code), but the snippet is still no redrawn.
Any ideas what am I doing wrong?
- Tomáš Votruba
- Moderator | 1114
Hi, place snippets into component's template:
{snippet}
..
{/}
And in control's handle call:
$this->redrawControl();
That should be enough.