Troubleshooting

Views package issues and fixes.

Template Issues

Template not found

Problem: View [admin/settings] not found

Cause: Wrong path or missing file.

Fix: Verify path configuration:

// Check path exists
$path = $context->path('resources/views');
if (!is_dir($path)) {
    throw new \RuntimeException("Views directory not found: {$path}");
}

$view->setPath($path);

Variables undefined

Problem: Undefined variable $user in template.

Cause: Variable not passed to render.

Fix: Pass all required data:

// Bad: Missing variable
$view->render('user/show');

// Good: Pass data
$view->render('user/show', [
    'user' => $user,
    'roles' => $roles,
]);

Layout Issues

Layout not rendering

Problem: Content shows without layout wrapper.

Cause: Layout not specified or wrong path.

Fix: Set layout in template:

<!-- Child template -->
<?php $this->layout('layouts/admin'); ?>

<?php $this->section('content'); ?>
    <h1>Content here</h1>
<?php $this->endSection(); ?>

Sections not appearing

Problem: $this->yieldSection('content') shows nothing.

Cause: Section not defined or wrong name.

Fix: Match section names exactly:

// Child: define section
<?php $this->section('content'); ?>
    ...
<?php $this->endSection(); ?>

// Layout: yield section (name must match)
<?php $this->yieldSection('content'); ?>

Escaping Issues

HTML stripped unexpectedly

Problem: HTML in variable shows as text.

Cause: Over-escaping with esc_html().

Fix: Use appropriate escaper:

// For plain text
echo esc_html($title);

// For safe HTML content
echo wp_kses_post($content);

// For known-safe HTML
echo $trustedHtml; // Be careful!