ADR-003 - Template-Engine
ADR-003: Template-Engine (Smarty)
Abschnitt betitelt „ADR-003: Template-Engine (Smarty)“Architecture Decision Record für XOOPS’s Übernahme der Smarty Template-Engine.
Akzeptiert - Kernentscheidung seit XOOPS 2.0
Evolving - Migration zu Smarty 4/5 geplant für XOOPS 4.0
Context
Abschnitt betitelt „Context“XOOPS benötigte eine Templating-Lösung, die folgende Anforderungen erfüllte:
- Trennen Sie Präsentation von Geschäftslogik
- Ermöglichen Sie Theme-Designern die Arbeit ohne PHP-Kenntnisse
- Unterstützen Sie Template-Vererbung und Includes
- Bieten Sie Caching für Leistung
- Ermöglichen Sie benutzerdefinierte Templates
- Unterstützen Sie Internationalisierung
Decision Diagram
Abschnitt betitelt „Decision Diagram“flowchart TB subgraph "PHP Layer" A[Module Controller] B[Template Variables] end
subgraph "Smarty Engine" C[Smarty Core] D[Template Compiler] E[Cache Manager] end
subgraph "Templates" F[Module Templates] G[Theme Templates] H[Block Templates] end
subgraph "Output" I[Compiled PHP] J[Cached HTML] K[Final HTML] end
A --> B B --> C C --> D C --> E D --> F D --> G D --> H F --> I G --> I H --> I E --> J I --> K J --> KDecision
Abschnitt betitelt „Decision“Wir werden Smarty als Template-Engine verwenden, weil:
1. Separation of Concerns
Abschnitt betitelt „1. Separation of Concerns“// PHP (Controller) - Business logic$items = $itemHandler->getPublishedItems();$xoopsTpl->assign('items', $items);
// Smarty (View) - Presentation// templates/items.tpl{* Smarty template - No PHP logic *}<{foreach item=item from=$items}> <article> <h2><{$item.title}></h2> <p><{$item.summary}></p> </article><{/foreach}>2. XOOPS-Begrenzer
Abschnitt betitelt „2. XOOPS-Begrenzer“XOOPS verwendet <{ und }> statt Standard { }:
{* Standard Smarty *}{$variable}
{* XOOPS Smarty - Avoids JavaScript conflicts *}<{$variable}>3. Template-Hierarchie
Abschnitt betitelt „3. Template-Hierarchie“graph TB A[Theme Master Template<br>theme.html] --> B[Module Template<br>module_index.tpl] A --> C[Block Templates<br>block_*.tpl] B --> D[Partial Templates<br>_header.tpl] B --> E[Partial Templates<br>_footer.tpl]
style A fill:#f9f,stroke:#333 style B fill:#9ff,stroke:#333 style C fill:#ff9,stroke:#3334. Template-Speicherung
Abschnitt betitelt „4. Template-Speicherung“- Datenbank: Angepasste Templates speichern für Rückbelegfähigkeit
- Dateisystem: Ursprüngliche Templates in Modulverzeichnissen
- Cache: Kompilierte Templates für Leistung
Smarty-Konfiguration
Abschnitt betitelt „Smarty-Konfiguration“// XOOPS Smarty initialization$xoopsTpl = new XoopsTpl();
// Custom delimiters$xoopsTpl->left_delim = '<{';$xoopsTpl->right_delim = '}>';
// Caching$xoopsTpl->caching = XOOPS_TEMPLATE_CACHE;$xoopsTpl->cache_lifetime = 3600;
// Security$xoopsTpl->security_policy = new Smarty_Security($xoopsTpl);$xoopsTpl->security_policy->php_functions = [];$xoopsTpl->security_policy->php_modifiers = ['escape', 'count'];Template-Features verwendet
Abschnitt betitelt „Template-Features verwendet“Variables
Abschnitt betitelt „Variables“{* Simple variable *}<{$title}>
{* Object property *}<{$item.title}>
{* With modifier *}<{$content|truncate:200:'...'}>
{* Escaped output *}<{$userInput|escape:'html'}>Kontrollstrukturen
Abschnitt betitelt „Kontrollstrukturen“{* Conditional *}<{if $isAdmin}> <a href="admin.php">Admin</a><{elseif $isUser}> <a href="profile.php">Profile</a><{else}> <a href="login.php">Login</a><{/if}>
{* Loop *}<{foreach item=item from=$items name=itemloop}> <{$smarty.foreach.itemloop.index}>: <{$item.title}><{/foreach}>Includes
Abschnitt betitelt „Includes“{* Include another template *}<{include file="db:mymodule_header.tpl"}>
{* Include with variables *}<{include file="db:mymodule_item.tpl" item=$currentItem}>
{* Include from theme *}<{include file="file:$theme_path/partials/sidebar.tpl"}>Consequences
Abschnitt betitelt „Consequences“Positiv
Abschnitt betitelt „Positiv“- Designer-freundlich: HTML-ähnliche Syntax
- Caching: Eingebautes Template-Caching
- Sicherheit: PHP-Code-Isolation
- Flexibilität: Modifizierer, Funktionen, Plugins
- Kustomisierung: Benutzer können Templates ändern
- Community: Großes Smarty-Ökosystem
Negativ
Abschnitt betitelt „Negativ“- Lernkurve: Smarty-spezifische Syntax
- Overhead: Compilierungsschritt erforderlich
- Debugging: Template-Fehler können kryptisch sein
- Versions-Probleme: Breaking Changes zwischen Versionen
Mitigations
Abschnitt betitelt „Mitigations“- Learning: Umfassende Dokumentation
- Performance: Aggressives Caching
- Debugging: Debug-Konsole, klare Fehlermeldungen
- Versions: Kompatibilitätsebene in XOOPS
Versionsgeschichte
Abschnitt betitelt „Versionsgeschichte“timeline title Smarty in XOOPS 2003 : Smarty 2.x : Initial integration 2013 : Smarty 3.0 : XOOPS 2.5.5 2020 : Smarty 3.1 : XOOPS 2.5.10 2026 : Smarty 4/5 : XOOPS 4.0Migration: Smarty 3 zu 4/5
Abschnitt betitelt „Migration: Smarty 3 zu 4/5“Breaking Changes
Abschnitt betitelt „Breaking Changes“{* Smarty 3 - Deprecated *}<{php}>echo date('Y');<{/php}>
{* Smarty 4+ - Use modifiers or assign from PHP *}<{$current_year}>
{* Smarty 3 - {section} deprecated *}<{section name=i loop=$items}> <{$items[i].title}><{/section}>
{* Smarty 4+ - Use {foreach} *}<{foreach $items as $item}> <{$item.title}><{/foreach}>Kompatibilitätsebene
Abschnitt betitelt „Kompatibilitätsebene“XOOPS bietet eine Kompatibilitätsebene für reibungslose Übergänge:
// XoopsTpl extends Smarty with compatibility methodsclass XoopsTpl extends Smarty{ public function assign($tpl_var, $value = null) { // Handles both Smarty 3 and 4 syntax return parent::assign($tpl_var, $value); }}Alternatives Considered
Abschnitt betitelt „Alternatives Considered“1. Twig
Abschnitt betitelt „1. Twig“Pros: Modern, Symfony ecosystem Cons: Different syntax, migration effort Decision: Possible future option for XOOPS 3.x
2. Blade (Laravel)
Abschnitt betitelt „2. Blade (Laravel)“Pros: Clean syntax, popular Cons: Laravel-specific Decision: Not suitable for standalone use
3. Native PHP Templates
Abschnitt betitelt „3. Native PHP Templates“Pros: No learning curve, fast Cons: Security risks, no separation Decision: Rejected for maintainability
Related Decisions
Abschnitt betitelt „Related Decisions“- ADR-001: Modular Architecture
- ADR-002: Database Abstraction
References
Abschnitt betitelt „References“- Smarty Documentation: https://www.smarty.net/docs/en/
- XOOPS Template System Guide
- MVC Pattern in Web Applications
#xoops #architecture #adr #smarty #templates #design-decision