Appearance
Templates System
This guide explains how the template system works in LamaPress, including template hierarchy, template files, and how templates integrate with sections and ACF fields.
Table of Contents
- Overview
- Template Files
- Template Registration
- Template Hierarchy
- Working with Templates
- Layout Block
- Best Practices
- Related Documentation
Overview
Templates in LamaPress are page-level files that define the structure of a page by loading sections. They use output buffering to wrap content in a layout block and automatically register ACF fields for all sections used.
Template Files
Templates are located in components/templates/ and follow WordPress template naming conventions.
Template Structure
A typical template file looks like this:
php
<?php
/* Template name: Contentpage */
defined('ABSPATH') || exit;
llStartTemplate();
llSection('hero_basic', 'contentpage_hero_basic');
llSection('rich_content', 'contentpage_rich_content');
llEndTemplate();Key Components:
/* Template name: ... */- Template name shown in WordPress adminllStartTemplate()- Begins output bufferingllSection(name, key)- Loads a section componentllEndTemplate()- Wraps content in layout block and outputs
Template Functions
llStartTemplate($routerName = false)
Begins output buffering for template content.
Parameters:
$routerName(string|false) - Optional router name for JavaScript
Usage:
php
llStartTemplate();
// or
llStartTemplate('custom-router');llEndTemplate()
Ends output buffering and wraps content in the layout block (components/blocks/layout/index.php).
Usage:
php
llEndTemplate();Template Registration
Post Type Templates
Templates are registered for post types via config/post-templates.php:
php
<?php
return [
'page' => [
'contentpage.php' => 'Contentpage',
'home.php' => 'Homepage',
'landingspage.php' => 'Landingspage',
],
'article' => [
'flex.php' => 'Flex',
],
];Structure:
- Key: Post type name
- Value: Array of
'template-file.php' => 'Display Name'pairs
Template Mapping
The system automatically:
- Scans
components/templates/for template files - Registers them with WordPress based on
config/post-templates.php - Makes them available in the WordPress admin template selector
Template Hierarchy
LamaPress follows WordPress template hierarchy, but templates are organized in components/templates/:
- Page Templates:
components/templates/*.php - Archive Templates: Standard WordPress hierarchy
- Single Templates: Standard WordPress hierarchy
Templates registered in config/post-templates.php appear in the WordPress admin when editing posts of that type.
Working with Templates
Creating a Template
Create Template File
Create
components/templates/my-template.php:php<?php /* Template name: My Template */ defined('ABSPATH') || exit; llStartTemplate(); llSection('hero_basic', 'my_template_hero'); llSection('rich_content', 'my_template_content'); llEndTemplate();Register Template
Add to
config/post-templates.php:phpreturn [ 'page' => [ 'my-template.php' => 'My Template', // ... other templates ], ];Select Template
In WordPress admin, edit a page and select "My Template" from the template dropdown.
Loading Sections
Use llSection() to load sections:
php
llSection('section_name', 'unique_key');Parameters:
section_name- Section directory name (e.g., 'hero_basic')unique_key- Unique identifier for ACF fields (e.g., 'page_hero_1')
Example:
php
llStartTemplate();
llSection('hero_basic', 'homepage_hero');
llSection('flexible', 'homepage_flexible');
llSection('rich_content', 'homepage_content');
llEndTemplate();ACF Field Keys
Each section needs a unique key for ACF fields. Follow these patterns:
- Template-specific:
{template_name}_{section_name}(e.g.,homepage_hero) - Page-specific:
page_{page_id}_{section_name}(for dynamic pages) - Unique: Use descriptive, unique keys to avoid conflicts
Best Practice: Use template name prefix for consistency:
php
llSection('hero_basic', 'contentpage_hero');
llSection('rich_content', 'contentpage_content');Layout Block
The llEndTemplate() function automatically wraps template content in the layout block (components/blocks/layout/index.php). This block provides:
- Page wrapper structure
- Header/footer integration
- Consistent page layout
You don't need to manually include the layout block - llEndTemplate() handles it.
Best Practices
1. Unique Keys
Always use unique, descriptive keys for ACF fields:
php
// Good
llSection('hero_basic', 'homepage_hero');
llSection('hero_basic', 'about_hero');
// Bad (conflicts)
llSection('hero_basic', 'hero');
llSection('hero_basic', 'hero');2. Template Organization
- Keep templates focused on a single page type
- Use descriptive template names
- Group related sections together
3. Section Order
Order sections logically:
- Hero sections first
- Content sections in the middle
- Footer/CTA sections last
Related Documentation
- Component System - How sections work
- ACF Integration - ACF field system
- PHP Functions Reference - Template functions
- Architecture Overview - System architecture
Next Steps:
- Review Component System to understand sections
- Check ACF Integration for field management
- See existing templates in
components/templates/for examples