ADR-003 - Sjabloonengine
ADR-003: Sjabloonengine (Smarty)
Section titled “ADR-003: Sjabloonengine (Smarty)”Architectuurbeslissingsrecord voor de adoptie door XOOPS van de Smarty-sjabloonengine.
Status
Section titled “Status”Geaccepteerd - Kernbeslissing sinds XOOPS 2.0
Evoluerend - Migratie naar Smarty 4/5 gepland voor XOOPS 4.0
Context
Section titled “Context”XOOPS had een sjabloonoplossing nodig die:
- Aparte presentatie van bedrijfslogica
- Laat thema-ontwerpers werken zonder kennis van PHP
- Ondersteuning van sjabloonovererving en -includes
- Zorg voor caching voor prestaties
- Schakel door de gebruiker aanpasbare sjablonen in
- Ondersteun internationalisering
Beslissingsdiagram
Section titled “Beslissingsdiagram”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 --> KBesluit
Section titled “Besluit”We gebruiken Smarty als sjabloonengine omdat:
1. Scheiding van zorgen
Section titled “1. Scheiding van zorgen”// 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 scheidingstekens
Section titled “2. XOOPS scheidingstekens”XOOPS gebruikt <{ en }> in plaats van standaard { }:
{* Standard Smarty *}{$variable}
{* XOOPS Smarty - Avoids JavaScript conflicts *}<{$variable}>3. Sjabloonhiërarchie
Section titled “3. Sjabloonhiërarchie”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. Sjabloonopslag
Section titled “4. Sjabloonopslag”- Database: aangepaste sjablonen opgeslagen voor herstelmogelijkheden
- Bestandssysteem: originele sjablonen in modulemappen
- Cache: samengestelde sjablonen voor prestaties
Smarty-configuratie
Section titled “Smarty-configuratie”// 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'];Gebruikte sjabloonfuncties
Section titled “Gebruikte sjabloonfuncties”Variabelen
Section titled “Variabelen”{* Simple variable *}<{$title}>
{* Object property *}<{$item.title}>
{* With modifier *}<{$content|truncate:200:'...'}>
{* Escaped output *}<{$userInput|escape:'html'}>Controlestructuren
Section titled “Controlestructuren”{* 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}>Inclusief
Section titled “Inclusief”{* 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"}>Gevolgen
Section titled “Gevolgen”Positief
Section titled “Positief”- Ontwerpervriendelijk: HTML-achtige syntaxis
- Caching: ingebouwde sjablooncaching
- Beveiliging: PHP-code-isolatie
- Flexibiliteit: modificaties, functies, plug-ins
- Aanpassing: gebruikers kunnen sjablonen wijzigen
- Gemeenschap: Groot Smarty-ecosysteem
Negatief
Section titled “Negatief”- Leercurve: Smarty-specifieke syntaxis
- Overhead: Compilatiestap vereist
- Foutopsporing: sjabloonfouten kunnen cryptisch zijn
- Versieproblemen: belangrijke wijzigingen tussen versies
Mitigaties
Section titled “Mitigaties”- Leren: uitgebreide documentatie
- Prestaties: agressieve caching
- Debugging: Debug console, wis foutmeldingen
- Versies: compatibiliteitslaag in XOOPS
Versiegeschiedenis
Section titled “Versiegeschiedenis”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.0Migratie: Smarty 3 naar 4/5
Section titled “Migratie: Smarty 3 naar 4/5”Brekende veranderingen
Section titled “Brekende veranderingen”{* 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}>Compatibiliteitslaag
Section titled “Compatibiliteitslaag”XOOPS biedt een compatibiliteitslaag voor vloeiende overgangen:
// 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); }}Alternatieven overwogen
Section titled “Alternatieven overwogen”1. Takje
Section titled “1. Takje”Voordelen: Modern Symfony-ecosysteem Nadelen: verschillende syntaxis, migratie-inspanningen Beslissing: Mogelijke toekomstige optie voor XOOPS 3.x
2. Mes (Laravel)
Section titled “2. Mes (Laravel)”Voordelen: Schone syntaxis, populair Nadelen: Laravel-specifiek Beslissing: Niet geschikt voor zelfstandig gebruik
3. Native PHP-sjablonen
Section titled “3. Native PHP-sjablonen”Voordelen: Geen leercurve, snel Nadelen: veiligheidsrisico’s, geen scheiding Beslissing: afgewezen vanwege onderhoudbaarheid
Gerelateerde beslissingen
Section titled “Gerelateerde beslissingen”- ADR-001: modulaire architectuur
- ADR-002: Database-abstractie
Referenties
Section titled “Referenties”- Smarty-documentatie: https://www.smarty.net/docs/en/
- XOOPS-sjabloonsysteemhandleiding
- MVC-patroon in webapplicaties
#xoops #architectuur #adr #Smarty #templates #design-decision