ADR-003 - टेम्पलेट इंजन
ADR-003: टेम्पलेट इंजन (Smarty)
Section titled “ADR-003: टेम्पलेट इंजन (Smarty)”XOOPS द्वारा Smarty टेम्पलेट इंजन को अपनाने के लिए आर्किटेक्चर निर्णय रिकॉर्ड।
स्थिति
Section titled “स्थिति”स्वीकृत - XOOPS 2.0 के बाद से मुख्य निर्णय
विकसित हो रहा है - XOOPS 4.0 के लिए Smarty 4/5 पर माइग्रेशन की योजना बनाई गई है
प्रसंग
Section titled “प्रसंग”XOOPS को एक टेम्प्लेटिंग समाधान की आवश्यकता है जो:
- प्रस्तुतिकरण को व्यावसायिक तर्क से अलग करें
- थीम डिजाइनरों को PHP ज्ञान के बिना काम करने की अनुमति दें
- समर्थन टेम्पलेट विरासत और शामिल हैं
- प्रदर्शन के लिए कैशिंग प्रदान करें
- उपयोगकर्ता-अनुकूलन योग्य टेम्पलेट सक्षम करें
- अंतर्राष्ट्रीयकरण का समर्थन करें
निर्णय आरेख
Section titled “निर्णय आरेख”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 --> Kहम टेम्पलेट इंजन के रूप में Smarty का उपयोग करेंगे क्योंकि:
1. चिंताओं का पृथक्करण
Section titled “1. चिंताओं का पृथक्करण”// 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 डिलीमीटर
Section titled “2. XOOPS डिलीमीटर”XOOPS मानक { } के बजाय <{ और }> का उपयोग करता है:
{* Standard Smarty *}{$variable}
{* XOOPS Smarty - Avoids JavaScript conflicts *}<{$variable}>3. टेम्पलेट पदानुक्रम
Section titled “3. टेम्पलेट पदानुक्रम”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. टेम्पलेट संग्रहण
Section titled “4. टेम्पलेट संग्रहण”- डेटाबेस: रिवर्ट क्षमता के लिए संग्रहीत अनुकूलित टेम्पलेट
- फ़ाइल सिस्टम: मॉड्यूल निर्देशिकाओं में मूल टेम्पलेट
- कैश: प्रदर्शन के लिए संकलित टेम्पलेट
Smarty कॉन्फ़िगरेशन
Section titled “Smarty कॉन्फ़िगरेशन”// 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'];प्रयुक्त टेम्प्लेट सुविधाएँ
Section titled “प्रयुक्त टेम्प्लेट सुविधाएँ”{* Simple variable *}<{$title}>
{* Object property *}<{$item.title}>
{* With modifier *}<{$content|truncate:200:'...'}>
{* Escaped output *}<{$userInput|escape:'html'}>नियंत्रण संरचनाएँ
Section titled “नियंत्रण संरचनाएँ”{* 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}>शामिल है
Section titled “शामिल है”{* 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"}>परिणाम
Section titled “परिणाम”सकारात्मक
Section titled “सकारात्मक”- डिज़ाइनर-अनुकूल: HTML-जैसा वाक्यविन्यास
- कैशिंग: अंतर्निहित टेम्पलेट कैशिंग
- सुरक्षा: PHP कोड अलगाव
- लचीलापन: संशोधक, फ़ंक्शन, प्लगइन्स
- अनुकूलन: उपयोगकर्ता टेम्पलेट्स को संशोधित कर सकते हैं
- समुदाय: बड़ा Smarty पारिस्थितिकी तंत्र
नकारात्मक
Section titled “नकारात्मक”- सीखने की अवस्था: Smarty-विशिष्ट वाक्यविन्यास
- ओवरहेड: संकलन चरण आवश्यक
- डीबगिंग: टेम्प्लेट त्रुटियाँ गुप्त हो सकती हैं
- संस्करण मुद्दे: संस्करणों के बीच परिवर्तन को तोड़ना
- सीखना: व्यापक दस्तावेज़ीकरण
- प्रदर्शन: आक्रामक कैशिंग
- डीबगिंग: डीबग कंसोल, त्रुटि संदेश साफ़ करें
- संस्करण: XOOPS में संगतता परत
संस्करण इतिहास
Section titled “संस्करण इतिहास”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.0माइग्रेशन: Smarty 3 से 4/5
Section titled “माइग्रेशन: Smarty 3 से 4/5”परिवर्तन तोड़ना
Section titled “परिवर्तन तोड़ना”{* 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}>अनुकूलता परत
Section titled “अनुकूलता परत”XOOPS सुचारू बदलाव के लिए एक अनुकूलता परत प्रदान करता है:
// 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); }}विकल्पों पर विचार किया गया
Section titled “विकल्पों पर विचार किया गया”1. टहनी
Section titled “1. टहनी”पेशेवर: आधुनिक, सिम्फनी पारिस्थितिकी तंत्र विपक्ष: भिन्न वाक्यविन्यास, माइग्रेशन प्रयास निर्णय: XOOPS 3.x के लिए संभावित भविष्य विकल्प
2. ब्लेड (लारवेल)
Section titled “2. ब्लेड (लारवेल)”पेशेवर: स्वच्छ वाक्यविन्यास, लोकप्रिय विपक्ष: लारवेल-विशिष्ट निर्णय: अकेले उपयोग के लिए उपयुक्त नहीं है
3. मूल PHP टेम्पलेट्स
Section titled “3. मूल PHP टेम्पलेट्स”पेशेवर: कोई सीखने की अवस्था नहीं, तेज़ नुकसान: सुरक्षा जोखिम, कोई अलगाव नहीं निर्णय: रखरखाव के कारण अस्वीकृत
##संबंधित निर्णय
- ADR-001: मॉड्यूलर आर्किटेक्चर
- ADR-002: डेटाबेस एब्स्ट्रैक्शन
सन्दर्भ
Section titled “सन्दर्भ”- Smarty दस्तावेज़ीकरण: https://www.smarty.net/docs/en/
- XOOPS टेम्पलेट सिस्टम गाइड
- वेब अनुप्रयोगों में एमवीसी पैटर्न
#xoops #आर्किटेक्चर #adr #smarty #टेम्पलेट्स #डिज़ाइन-निर्णय