PHP code example of millancore / pesto
1. Go to this page and download the library: Download millancore/pesto library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
millancore / pesto example snippets
use MillanCore\Pesto\PestoFactory;
$pesto = PestoFactory::create([
templatesPath: __DIR__ . '/views',
cachePath: __DIR__ . '/cache',
// [ New CustomFilters(), ... ]
]);
$pesto->make('view.php', ['user' => $user]);
// CustomFilter.php
#[AsFilter(name: 'truncate')]
public function truncate(string $value, int $length, string $end = '...') : string
{
//...
}
$pesto = PestoFactory::create([
templatesPath: __DIR__ . '/views',
cachePath: __DIR__ . '/cache', [
New CustomFilter(),
]
]);
html
<ul>
<li php-foreach="range(1, 10) as $number" php-if="$number > 7">Item {{ $number }}</li>
</ul>
html
<ul>
<template php-foreach="range(1, 10) as $number">
<li php-if="$number > 7">Item {{ $number }}</li>
</template>
</ul>
html
<!--- views/home.php -->
<template php-partial="layouts/app.php" php-with="['title' => 'Home']">
<!-- Named slot -->
<nav php-slot="header">
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
<!--Main Slot -->
<section>
<h1>Home</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quae.</p>
<section>
</template
html
<template php-partial="list.php">
<li>Item</li>
<li>
<ul php-partial="list.php">
<li>nested item</li>
....
</ul>
</li>
</template>
html
<p php-if="$user->isAdmin()">Admin</p>
<p php-elseif="$user->isModerator()">Moderator</p>
<p php-else>Guest</p>
html
<li php-foreach="$list as $item">{{ $item }}</li>
html
<ul>
<template php-foreach="$users as $user" php-if="$user->isAdmin()">
<li>{{ $user->name | title }} - {{ $user->email }}</li>
</template>
</ul>