@if (!empty($templates))
@foreach (array_reverse($templates) as $index => $template)
{{ $template['name'] }}
Category: {{ $template['category'] }} | Language: {{ $template['language'] }}
@php
$bodyText = 'N/A';
foreach ($template['components'] ?? [] as $component) {
if ($component['type'] === 'BODY') {
$bodyText = $component['text'];
}
}
// Convert WhatsApp formatting
$bodyText = htmlentities($bodyText, ENT_QUOTES, 'UTF-8');
$bodyText = preg_replace('/\*(.*?)\*/', '$1', $bodyText);
$bodyText = preg_replace('/_(.*?)_/', '$1', $bodyText);
$bodyText = preg_replace('/~(.*?)~/', '$1', $bodyText);
$bodyText = preg_replace('/```(.*?)```/', '$1
', $bodyText);
// Preserve placeholders like {{1}}, {{2}}
$bodyText = preg_replace('/\{\{(\d+)\}\}/', '{{ $1 }}', $bodyText);
// Remove extra blank lines and convert newlines to
tags
$bodyText = trim($bodyText);
$bodyText = preg_replace("/(\r?\n){2,}/", "\n", $bodyText);
$bodyText = nl2br($bodyText);
@endphp
Message Content
{!! $bodyText !!}
Example Data
@php
$exampleData = [];
foreach ($template['components'] ?? [] as $component) {
if ($component['type'] === 'BODY' && isset($component['example']['body_text'])) {
$exampleData = $component['example']['body_text'][0];
}
}
@endphp
@if (!empty($exampleData))
@foreach ($exampleData as $data)
- {{ $data }}
@endforeach
@else
N/A
@endif