Appearance
Data Flow
This guide explains how data flows from ACF fields through templates to components in LamaPress.
Table of Contents
- Overview
- Data Flow Architecture
- Registration Phase
- Rendering Phase
- Data Flow Examples
- Best Practices
- Related Documentation
Overview
LamaPress uses an automatic data flow system that:
- Scans templates for section usage
- Extracts ACF field definitions from component
acf.phpfiles - Registers field groups with WordPress/ACF
- Retrieves field values during template rendering
- Passes data to components via props or variables
Data Flow Architecture
Template File → llSection() → Section ACF → Field Registration → Field Retrieval → Component RenderingFlow Steps:
- Template calls
llSection(name, key) - System scans template for section calls
- System loads section's
acf.phpfile - System generates ACF field group with unique keys
- WordPress/ACF registers field group
- Template renders and calls
llField(name, key) - ACF returns field value
- Component receives data and renders
Registration Phase
Template Scanning
On every request, llSections() is called, which:
- Scans template files in
components/templates/ - Extracts
llSection()calls using regex - Identifies section names and keys
Example Template:
php
llSection('hero_basic', 'homepage_hero');
llSection('rich_content', 'homepage_content');Extracted Data:
- Section:
hero_basic, Key:homepage_hero - Section:
rich_content, Key:homepage_content
Section Field Extraction
For each section found:
- Loads
acf.phpfrom section directory - Extracts field definitions (
$groupFields) - Gets section metadata (
$name,$title,$key)
Example acf.php:
php
<?php
$key = 'hero_basic_key';
$name = 'hero_basic';
$title = 'Hero Basic';
$groupFields = [
[
'key' => 'title',
'label' => 'Title',
'name' => 'title',
'type' => 'text',
],
];ACF Field Group Generation
System generates ACF field groups:
- Creates accordion tabs for each section
- Prefixes field keys with section key
- Registers field group with WordPress
Generated Structure:
php
[
'key' => 'template_home',
'title' => 'Fixed content sections',
'fields' => [
[
'key' => 'homepage_hero',
'label' => '1 Hero Basic',
'type' => 'accordion',
],
[
'key' => 'homepage_hero_title',
'label' => 'Title',
'name' => 'homepage_hero_title',
'type' => 'text',
],
// ... more fields
],
'location' => [
[
[
'param' => 'page_template',
'operator' => '==',
'value' => 'components/templates/home.php',
],
],
],
]Rendering Phase
Template Execution
When WordPress renders a page:
- Selects template based on page type
- Executes template file (
components/templates/*.php) - Calls
llStartTemplate()to begin output buffering
Section Loading
Template calls llSection(name, key):
php
llSection('hero_basic', 'homepage_hero');What happens:
- System locates
components/sections/hero_basic/index.php - Includes the template file
- Section template receives
$keyand$sectionvariables
Field Retrieval
Section template retrieves fields using llField():
php
<?php
$title = llField('title', $key, $section);
$content = llField('content', $key, $section);
?>Field Resolution:
- If
$sectionprovided: Returns$section['title'] - If only
$keyprovided: Callsget_field($key . '_title') - Returns
nullif field doesn't exist
Component Rendering
Sections can load blocks and parts:
php
<?php
llBlock('rich_content', [
'content' => $content,
'classes' => 'custom-class',
]);
?>Data Flow:
- Block receives props via
extract($props) - Block template accesses variables directly
- Block can load parts with data
Data Flow Examples
Simple Section
Template:
php
llSection('hero_basic', 'homepage_hero');Section ACF:
php
$groupFields = [
['key' => 'title', 'name' => 'title', 'type' => 'text'],
];Section Template:
php
<?php
$title = llField('title', $key, $section);
?>
<h1><?= esc_html($title) ?></h1>Result:
- Field registered as
homepage_hero_title - Value retrieved via
get_field('homepage_hero_title') - Rendered in template
Flexible Content
Template:
php
llSection('flexible', 'homepage_flexible');System:
- Scans all sections (or specified list)
- Creates flexible content layouts
- Each layout uses section's fields
Result:
- CMS shows flexible content field
- User can add sections dynamically
- Each section uses its own field definitions
Nested Components
Section Template:
php
<?php
$items = llField('items', $key, $section);
foreach ($items as $item) {
llBlock('card', [
'title' => $item['title'],
'content' => $item['content'],
]);
}
?>Data Flow:
- Section retrieves repeater field
- Loops through items
- Passes item data to block
- Block renders with data
Best Practices
1. Unique Keys
Always use unique, descriptive keys:
php
// Good
llSection('hero_basic', 'homepage_hero');
llSection('hero_basic', 'about_hero');
// Bad (conflicts)
llSection('hero_basic', 'hero');
llSection('hero_basic', 'hero');2. Field Naming
Use consistent field names:
php
// Good
$title = llField('title', $key, $section);
$subtitle = llField('subtitle', $key, $section);
// Avoid
$heading = llField('heading', $key, $section);
$subheading = llField('subheading', $key, $section);3. Data Validation
Always check for field existence:
php
<?php
$title = llField('title', $key, $section);
if ($title) {
echo '<h1>' . esc_html($title) . '</h1>';
}
?>Related Documentation
- Component System - Component structure
- ACF Integration - ACF field system
- Templates System - Template usage
- PHP Functions Reference - Helper functions
Next Steps:
- Review ACF Integration for field definitions
- Check Component System for component structure
- See Templates System for template usage