How to redraw just one snippet in a component
- netteman
- Member | 126
Hi,
is it possible to redraw just one snippet defined in a component?
I tried using snippetArea in various places, but all I got was empty JSONs or errors.
Component
<?php
namespace App\Components;
class Random extends \Nette\Application\UI\Control{
public function renderTest(){
$this->template->a = \Nette\Utils\Random::generate(5);
$this->template->b = \Nette\Utils\Random::generate(5);
$this->template->c = \Nette\Utils\Random::generate(5);
$this->template->render(__DIR__.'/test.latte');
}
}
test.latte
{block content}
{snippet a}
{$a} <a href="{plink :a!}" class="ajax">Refresh</a>
{/snippet}
{snippet b}
{$b} <a href="{plink :c!}" class="ajax">Refresh</a>
{/snippet}
{snippet c}
{$c} <a href="{plink :c!}" class="ajax">Refresh</a>
{/snippet}
Presenter
<?php
declare(strict_types=1);
namespace App\Presenters;
use Nette;
final class ComponentPresenter extends Nette\Application\UI\Presenter
{
public function renderDefault(){
}
public function createComponentRandom(){
return new \App\Components\Random;
}
public function handleA(){
/*
I tried different commands here
$this->getComponent('random')->redrawControl('a');
ends with the "Call to undefined method App\Components\Random::render()" error
$this->redrawControl('name of snippet area defined in the presenter template');
does nothing
*/
$this->redrawControl('a');
}
public function handleB(){
$this->redrawControl('b');
}
public function handleC(){
$this->redrawControl('c');
}
}
default.latte
{block content}
{control random:test}
Last edited by netteman (2021-12-21 20:10)
- Rick Strafy
- Nette Blogger | 81
Hi, try $this['random']->redrawControl('a');
or define those
handle
methods in component and call only link, not plink.
- netteman
- Member | 126
Thanks for your reply
Rick Strafy wrote:
Hi, try $this[‘random’]->redrawControl(‘a’); or define those handle methods in component and call only link, not plink.
This ends with Call to undefined method App\Components\Random::render()
Rick Strafy wrote:
And why do you have renderTest and not just render? o.O
I'm learning how to use snippets – this is just for testing purposes. Plus, I usually use more views (or whatever it's called) in components. For example in an article component I'd use renderThumbnail(), renderFull() etc.
Last edited by netteman (2021-12-22 06:53)
- BigCharlie
- Member | 283
netteman wrote:
For example in an article component I'd use renderThumbnail(), renderFull() etc.
I guess that's the problem…
- netteman
- Member | 126
BigCharlie wrote:
netteman wrote:
For example in an article component I'd use renderThumbnail(), renderFull() etc.I guess that's the problem…
Hmm, the docs don't object against it
Sometimes a component can consist of several parts that we want to render separately. For each of them we will create own rendering method, here is for example renderPaginator():