Zing. compile-to-PHP template engine GitHub ↗

Attribute Helpers

Zing provides helpers for conditional and dynamic HTML attributes.

@class

<div @class(['card', 'card-active' => $isActive, 'card-error' => $hasErrors])>

Unkeyed entries always render. Keyed entries render only when their value is truthy.

@style

<div @style(['display: none' => !$isVisible, 'color: red' => $hasError])>

@style follows the same keyed/unkeyed rules as @class.

Boolean attributes

These directives emit the bare HTML boolean attribute when the condition is truthy:

<input type="checkbox" @checked($course->isPublished) />
<option @selected($status === 'draft')>Draft</option>
<input @disabled(!$user->canEdit) />
<input @readonly($isLocked) />
<input @required($field->isRequired()) />

@attributes

Spread an associative array as HTML attributes:

<button @attributes(['type' => 'submit', 'data-id' => $id, 'aria-label' => $label])>

Values are HTML-escaped. Keys whose value is null or false are skipped.