Skip to content

Instantly share code, notes, and snippets.

@aiphee
Created October 30, 2023 14:10
Show Gist options
  • Save aiphee/021a683e139f6cd16bb668d1440ad0db to your computer and use it in GitHub Desktop.
Save aiphee/021a683e139f6cd16bb668d1440ad0db to your computer and use it in GitHub Desktop.
Simple component test
{include ../../../Components/ProductTile/templates/test-block.latte with blocks}
{for $i = 0; $i < 500; $i++}
{include ptBlock 'index' => $i}
{/for}
<?php
declare(strict_types=1);
namespace App\Presenters;
use App\Components\ProductTile\ProductTileComponent;
use Nette;
use Nette\Application\UI\Multiplier;
final class HomePresenter extends Nette\Application\UI\Presenter
{
protected function createComponentProductTile(): Nette\Application\UI\Multiplier
{
return new Multiplier(fn(string $key) => new ProductTileComponent((int) $key));
}
}
{block content}
{for $i = 0; $i < 500; $i++}
{include ../../../Components/ProductTile/templates/test.latte 'index' => $i}
{/for}
<?php
declare(strict_types=1);
namespace App\Components\ProductTile;
use Nette\Application\UI\Control;
class ProductTileComponent extends Control
{
public function __construct(
private readonly int $index,
) {
}
public function render(): void
{
$this->template->render(
__DIR__ . '/templates/test.latte',
[
'index' => $this->index,
]
);
}
}
{define ptBlock}
<div>
<h3>{$index}</h3>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum eligendi enim est eum expedita iste nam nesciunt
numquam omnis, optio, quod recusandae repellendus saepe similique sint tenetur ullam ut voluptas.
</div>
{/define}
<div>
<h3>{$index}</h3>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum eligendi enim est eum expedita iste nam nesciunt
numquam omnis, optio, quod recusandae repellendus saepe similique sint tenetur ullam ut voluptas.
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment