Skip to main content

Template Example: Conditional HTML Effects

This example illustrates how to inject dynamic HTML formatting (such as red rejection tags or status badges) into template fields.

Workflow

1. Controller Data Injection

In JytManagementController.php, when an appointment is declined, the date string is formatted with inline HTML styling:

$signedDateFormatted = $appointment->signed_at
? $appointment->signed_at->format('Y-m-d')
: now()->format('Y-m-d');

$todayDateVal = ($appointment->status === 'declined')
? $signedDateFormatted . ' <span style="color: #dc3545; font-weight: bold;">(拒绝)</span>'
: $signedDateFormatted;

$data['date']['today'] = $todayDateVal;

2. Unescaped Output in Renderer

The template engine uses Blade's raw output syntax {!! $val !!} to allow inline HTML styling to render natively without escaping tags:

<div class="el-content" style="{{ $txtCss }}">{!! empty($val) ? ($el['placeholderId'] ?? $field) : $val !!}</div>

Output Preview

  • Accepted Appointment: 2026-08-24
  • Declined Appointment: 2026-08-24 (拒绝) (rendered as raw HTML: 2026-08-24 <span style="color: #dc3545; font-weight: bold;">(拒绝)</span>)