PHP code example of daun / statamic-latte

1. Go to this page and download the library: Download daun/statamic-latte 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/ */

    

daun / statamic-latte example snippets


use Daun\StatamicLatte\Components\Component;

class Alert extends Component
{
    public function __construct(
        public string $type = 'info',
    ) {}

    public function data(): array
    {
        return [...parent::data(), 'classes' => "alert alert-{$this->type}"];
    }
}

'cascade' => 'full',
latte
<nav n:ifcontent n:inner-foreach={$entries as $entry}>
  <a n:tag-if={$entry->link} href={$entry->link}>
    {$entry->title}
  </a>
</nav>
sh
php artisan vendor:publish --tag=statamic-latte-config
latte
{s:form:create as: form, in: contact}
    <form method="{$form->attrs->method}" action="{$form->attrs->action}">
        {foreach $form->fields as $field}
            <label>{$field->display}</label>
            <input type="text" name="{$field->name}" value="{$field->value}">
            {if $field->error}<span class="error">{$field->error}</span>{/if}
        {/foreach}
        <button type="submit">Send</button>
    </form>
{/s:form:create}
latte
<h1>{$entry->title}</h1>       {* text field → escaped, even if it holds <a> *}
<div>{$entry->content}</div>   {* markdown field → <p>…</p>, as markup *}
latte
{* partials/figure.latte *}

<figure>
    <img src="{$src}" alt="{$alt}">
    <figcaption>{slot caption}Default caption{/slot}</figcaption>
</figure>
latte
{* partials/table.latte *}

<table>
    {foreach $rows as $row}
        <tr>
            {slot row}
                <td>{$row}</td>
            {/slot}
        </tr>
    {/foreach}
</table>
latte
{* template *}

{var $class = 'highlight'}

{embed file 'partials.table', rows: $rows}
    {slot row}
        <td class={$class}>{$row}</td>
    {/slot}
{/embed}
latte
{* partials/table.latte *}

{define row, $cell}
    <td>{$cell}</td>
{/define}

<table>
    {foreach $rows as $row}
        <tr>{
latte
{cache for: '10 minutes'}
    {foreach $stocks as $stock}
        {$stock->fetchPrice()}
    {/foreach}
{/cache}
latte
<x-card n:if="$show">content</x-card>

<x-greeting n:foreach="$names as $name" name={$name}/>