{"id":26387715,"url":"https://github.com/sedteam/xtemplate","last_synced_at":"2025-03-17T08:36:40.605Z","repository":{"id":280671528,"uuid":"942749963","full_name":"sedteam/Xtemplate","owner":"sedteam","description":"PHP XTemplate SE","archived":false,"fork":false,"pushed_at":"2025-03-04T17:51:56.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-04T18:19:56.153Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sedteam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-04T16:02:12.000Z","updated_at":"2025-03-04T17:52:00.000Z","dependencies_parsed_at":"2025-03-04T18:19:57.892Z","dependency_job_id":"04a96774-f335-44d4-af83-36d5292a0713","html_url":"https://github.com/sedteam/Xtemplate","commit_stats":null,"previous_names":["sedteam/xtemplate"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sedteam%2FXtemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sedteam%2FXtemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sedteam%2FXtemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sedteam%2FXtemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sedteam","download_url":"https://codeload.github.com/sedteam/Xtemplate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244001620,"owners_count":20381802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-17T08:36:39.943Z","updated_at":"2025-03-17T08:36:40.590Z","avatar_url":"https://github.com/sedteam.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"XTemplate - PHP Templating Engine\n=================================\n\n![License: LGPL/BSD](https://img.shields.io/badge/License-LGPL%20%2F%20BSD-blue.svg) ![PHP Version](https://img.shields.io/badge/PHP-5.4%2B-brightgreen.svg)\n\n## Table of Contents\n\n1. [Introduction](#introduction)\n2. [Installation](#installation)\n3. [Basic Usage](#basic-usage)\n4. [Template Syntax](#template-syntax)\n5. [Blocks and Variables](#blocks-and-variables)\n6. [Conditional Logic](#conditional-logic)\n7. [Callback Functions](#callback-functions)\n8. [Error Handling](#error-handling)\n9. [Performance Optimization](#performance-optimization)\n10. [Contributing](#contributing)\n11. [License](#license)\n\nIntroduction\n------------\n\n**XTemplate** is a fast and lightweight PHP templating engine designed to separate PHP code logic from the presentation layer (HTML, XML, etc.). It enables developers to focus on programming while allowing designers to concentrate on design. Originally created by Barnabas Debreceni in 2000, it was enhanced by Jeremy Coates until 2007, and later improved within the Seditio fork (\u003c 180v). The current version includes significant updates by Alexander Tishov and the Seditio Team (2025), such as conditional logic, enhanced error handling, and optimized HTML compression.\n\n**Purpose**: Simplify the creation of dynamic web pages while maintaining clean code and high performance.\n\nInstallation\n------------\n\n1.  **Download the repository**:\n    \n        git clone https://github.com/sedteam/Xtemplate/xtemplate.git\n    \n2.  **Include in your project**: Copy `xtemplate.class.php` to your project directory and include it:\n    \n        \u003c?php\n        require_once 'xtemplate.class.php';\n        ?\u003e\n    \n\nFor upgrades:\n\n*   Test the new version on sample code.\n*   Back up the current version.\n*   Replace the old file with the new one and verify functionality.\n\nBasic Usage\n-----------\n\nCreate an `XTemplate` instance, assign variables, parse the template, and output the result:\n\n    \u003c?php\n    require_once 'xtemplate.class.php';\n    \n    $xtpl = new XTemplate('templates/example.tpl');\n    $xtpl-\u003eassign('TITLE', 'Hello, World!');\n    $xtpl-\u003eparse('MAIN');\n    $xtpl-\u003eout('MAIN');\n    ?\u003e\n\n**templates/example.tpl**:\n\n    \u003c!-- BEGIN: MAIN --\u003e\n    \u003ch1\u003e{TITLE}\u003c/h1\u003e\n    \u003c!-- END: MAIN --\u003e\n\n**Output**:\n\n    \u003ch1\u003eHello, World!\u003c/h1\u003e\n\nTemplate Syntax\n---------------\n\n### Variables\n\n*   Simple: `{VAR}` — replaced with the value of `VAR`.\n*   Arrays: `{ROW.ID}` — accesses `ROW['ID']`.\n*   Globals: `{PHP._SERVER.HTTP_HOST}` — accesses PHP global variables.\n\n### Blocks\n\n*   Block start: `\u003c!-- BEGIN: BLOCK_NAME --\u003e`.\n*   Block end: `\u003c!-- END: BLOCK_NAME --\u003e`.\n*   Nested blocks: Supported for complex structures.\n\nBlocks and Variables\n--------------------\n\nExample with nested blocks:\n\n    $xtpl-\u003eassign('USERS', [\n        ['NAME' =\u003e 'Alex', 'DETAILS' =\u003e ['AGE' =\u003e 30]],\n        ['NAME' =\u003e 'Maria', 'DETAILS' =\u003e ['AGE' =\u003e 25]]\n    ]);\n    $xtpl-\u003earray_loop('MAIN.USERS', 'USER', $xtpl-\u003evars['USERS']);\n    $xtpl-\u003eparse('MAIN');\n    $xtpl-\u003eout('MAIN');\n\nor\n\n    $users = [\n        ['NAME' =\u003e 'Alex', 'DETAILS' =\u003e ['AGE' =\u003e 30]],\n        ['NAME' =\u003e 'Maria', 'DETAILS' =\u003e ['AGE' =\u003e 25]]\n    ];\n    foreach ($users as $user) {\n        $xtpl-\u003eassign('USER', $user);\n        $xtpl-\u003eparse('MAIN.USERS');\n    }\n    $xtpl-\u003eparse('MAIN');\n    $xtpl-\u003eout('MAIN');\n\n**templates/example.tpl**:\n\n    \u003c!-- BEGIN: MAIN --\u003e\n    \u003cul\u003e\n        \u003c!-- BEGIN: USERS --\u003e\n        \u003cli\u003e{USER.NAME} ({USER.DETAILS.AGE} years)\u003c/li\u003e\n        \u003c!-- END: USERS --\u003e\n    \u003c/ul\u003e\n    \u003c!-- END: MAIN --\u003e\n\n**Output**:\n\n    \u003cul\u003e\n        \u003cli\u003eAlex (30 years)\u003c/li\u003e\n        \u003cli\u003eMaria (25 years)\u003c/li\u003e\n    \u003c/ul\u003e\n\n\\- **Dynamic Blocks**: Multi-level nested blocks with recursive parsing via `rparse`.  \n\\- **Auto-reset**: Sub-blocks reset after parsing the parent by default (disable with `clear_autoreset()`).  \n\\- **Null Strings**: Set defaults for unassigned variables or blocks:\n\n    $xtpl-\u003eset_null_string('Not specified', 'VAR');\n\nConditional Logic\n-----------------\n\nSupport for conditions with operators (`\u003e`, `\u003c`, `==`, `!=`, `\u0026\u0026`, `||`, etc.):\n\n    $age = 20;\n    $logged = true;\n    $xtpl-\u003eassign('USER_AGE', $age);\n    $xtpl-\u003eassign('USER_LOGGED_IN', $logged);\n    $xtpl-\u003eparse('MAIN');\n    $xtpl-\u003eout('MAIN');\n\n**templates/example.tpl**:\n\n    \u003c!-- BEGIN: MAIN --\u003e\n    \u003c!-- IF USER_AGE \u003e 18 \u0026\u0026 USER_LOGGED_IN --\u003e\n        \u003cp\u003eAccess granted.\u003c/p\u003e\n    \u003c!-- ELSE --\u003e\n        \u003cp\u003eAccess denied.\u003c/p\u003e\n    \u003c!-- ENDIF --\u003e\n    \u003c!-- END: MAIN --\u003e\n    \nor\n\n    \u003c!-- BEGIN: MAIN --\u003e\n    \u003c!-- IF {USER_AGE} \u003e 18 \u0026\u0026 {USER_LOGGED_IN} --\u003e\n        \u003cp\u003eAccess granted.\u003c/p\u003e\n    \u003c!-- ELSE --\u003e\n        \u003cp\u003eAccess denied.\u003c/p\u003e\n    \u003c!-- ENDIF --\u003e\n    \u003c!-- END: MAIN --\u003e\n    \nor \n\n    \u003c!-- BEGIN: MAIN --\u003e\n    \u003c!-- IF {PHP.age} \u003e 18 \u0026\u0026 {PHP.logged} --\u003e\n        \u003cp\u003eAccess granted.\u003c/p\u003e\n    \u003c!-- ELSE --\u003e\n        \u003cp\u003eAccess denied.\u003c/p\u003e\n    \u003c!-- ENDIF --\u003e\n    \u003c!-- END: MAIN --\u003e\n\n**Output**:\n\n    \u003cp\u003eAccess granted.\u003c/p\u003e\n\nCallback Functions\n------------------\n\nApply PHP functions to variables within the template:\n\n    $xtpl-\u003eassign('TEXT', 'hello, world');\n    $xtpl-\u003eparse('MAIN');\n    $xtpl-\u003eout('MAIN');\n\n**templates/example.tpl**:\n\n    \u003c!-- BEGIN: MAIN --\u003e\n    \u003cp\u003e{TEXT|strtoupper}\u003c/p\u003e\n    \u003c!-- END: MAIN --\u003e\n\n**Output**:\n\n    \u003cp\u003eHELLO, WORLD\u003c/p\u003e\n\nWith parameters:\n\n    \u003cp\u003e{TEXT|str_replace(\"world\",\"everyone\")}\u003c/p\u003e\n\n**Output**: `\u003cp\u003ehello, everyone\u003c/p\u003e`\n\nThe list of allowed functions is customizable via `$allowed_callbacks`.\n\nError Handling\n--------------\n\n\\- **Modes**: Configurable via `error_handling` (`log`, `display`, `both`, `none`).  \n\\- **Logging**: Errors are written to a file specified in `error_log_file`:\n\n    $xtpl = new XTemplate(['file' =\u003e 'example.tpl', 'error_handling' =\u003e 'both', 'error_log_file' =\u003e 'errors.log']);\n    $xtpl-\u003edebug = true;\n\nExample error output:\n\n    \u003c!-- XTemplate Errors for Block: MAIN --\u003e\n    \u003cb\u003e[XTemplate Errors]\u003c/b\u003e\u003cul\u003e\u003cli\u003eparse: blockname [unknown] does not exist (Context: File: example.tpl, Block: unknown, Time: 2025-03-04 12:00:00)\u003c/li\u003e\u003c/ul\u003e\n\nPerformance Optimization\n------------------------\n\n\\- **Speed**: The algorithm avoids recursive calls for block tree construction, making it one of the fastest templating engines with nested block support.  \n\\- **Compression**: Enable `compress_output` for HTML minification:\n\n    $xtpl-\u003ecompress_output = true;\n\n\\- **File Caching**: Repeated template file access is cached in `$filecache`.\n\nContributing\n------------\n\nWe welcome contributions! To get involved:\n\n1.  Fork the repository on [GitHub](https://github.com/sedteam/Xtemplate).\n2.  Submit a pull request with your changes.\n3.  Open an issue to report bugs or suggest ideas.\n\nAdditional resources:\n\n*   [seditio.org](http://seditio.org/)\n*   [SourceForge](http://sourceforge.net/projects/xtpl/)\n\nLicense\n-------\n\nXTemplate is dual-licensed under **LGPL** and **BSD**. See details in [license.txt](https://github.com/sedteam/Xtemplate/blob/main/license.txt).\n\nHistory\n-------\n\nXTemplate was created by Barnabas Debreceni (cranx) in 2000 as a simple and fast templating engine, inspired by the syntax of FastTemplate and QuickTemplate. The code was written from scratch in a single day without borrowing from other engines and optimized for speed with a unique block-processing algorithm.\n\nIn 2002, cranx handed the project over to Jeremy Coates (cocomp), who maintained it until 2007, releasing stable versions on SourceForge (last revision: `$Id: README.txt 16 2007-01-11 03:02:49Z cocomp $`). After a period of inactivity, the project was revived within the Seditio fork. In 2025, Alexander Tishov and the Seditio Team added modern features like RPN-based conditional logic, enhanced compression, and error handling.\n\nHistorical data:\n\n*   SVN: `$HeadURL: https://xtpl.svn.sourceforge.net/svnroot/xtpl/trunk/README.txt $`\n*   Latest versions: [SourceForge](http://sourceforge.net/projects/xtpl/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsedteam%2Fxtemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsedteam%2Fxtemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsedteam%2Fxtemplate/lists"}