Templates

An Atom template is an HTML file with expressions and directives that run on the server. On the product page, ProductPage.php loads the product and ProductPage.atom.html turns it into the HTML the browser receives. By default, Atom finds the template beside the page class.

From Model to HTML

The same template syntax works for pages and components. A template renders values from the model it is given. Here $this is the page instance. It provides the product, an availability label, and $finishes, a list of finish names such as ["Matte black", "Brass"].

ProductPage.atom.html (excerpt)
<article>
    <h1>{{ $this->product->name }}</h1>
    <p>{{ $this->availabilityLabel() }}</p>

    @if(!$this->product->inStock)
        <p>This product is currently unavailable.</p>
    @endif

    <label for="finish">Finish</label>
    <select id="finish" name="finish"
            :disabled="!$this->product->inStock || $this->finishes === []">
        @foreach($this->finishes as $finish)
            <option value="{{ $finish }}">{{ $finish }}</option>
        @empty
            <option>No finishes available</option>
        @endforeach
    </select>
</article>

The same finish value fills both the option's attribute and its visible label. Atom escapes both. The :disabled binding adds the boolean attribute when the product is out of stock or there are no finishes. The loop renders one option per finish and supplies a fallback for an empty list.

Template syntax explains each expression and directive. Components shows how to give reusable markup its own template and inputs.