{"id":20655244,"url":"https://github.com/ericsizemore/simple_tpl","last_synced_at":"2026-04-21T14:35:41.027Z","repository":{"id":148466674,"uuid":"176177938","full_name":"ericsizemore/simple_tpl","owner":"ericsizemore","description":"This class implements a simple template engine that works by replacing text.","archived":false,"fork":false,"pushed_at":"2026-04-20T10:34:39.000Z","size":1022,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-20T11:37:07.737Z","etag":null,"topics":["template","template-engine","text","text-replacement"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericsizemore.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"ko_fi":"ericsizemore","github":"ericsizemore"}},"created_at":"2019-03-18T00:33:44.000Z","updated_at":"2026-04-20T09:45:43.000Z","dependencies_parsed_at":"2026-03-17T20:04:43.664Z","dependency_job_id":null,"html_url":"https://github.com/ericsizemore/simple_tpl","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ericsizemore/simple_tpl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericsizemore%2Fsimple_tpl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericsizemore%2Fsimple_tpl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericsizemore%2Fsimple_tpl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericsizemore%2Fsimple_tpl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericsizemore","download_url":"https://codeload.github.com/ericsizemore/simple_tpl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericsizemore%2Fsimple_tpl/sbom","scorecard":{"id":380708,"data":{"date":"2025-08-11","repo":{"name":"github.com/ericsizemore/simple_tpl","commit":"128b87e3bf2b31a0cc89dddd6fa7de30c651e186"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":8.2,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":-1,"reason":"Found no human activity in the last 15 changesets","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":10,"reason":"30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: SECURITY.md:1","Info: Found linked content: SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1","Info: Found text in security policy: SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":10,"reason":"SAST tool is run on all commits","details":["Info: all commits (30) are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T15:22:40.414Z","repository_id":148466674,"created_at":"2025-08-18T15:22:40.414Z","updated_at":"2025-08-18T15:22:40.414Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32096137,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["template","template-engine","text","text-replacement"],"created_at":"2024-11-16T18:09:40.482Z","updated_at":"2026-04-21T14:35:41.018Z","avatar_url":"https://github.com/ericsizemore.png","language":"PHP","funding_links":["https://ko-fi.com/ericsizemore","https://github.com/sponsors/ericsizemore"],"categories":[],"sub_categories":[],"readme":"# Simple Template Engine - Text based template parser.\n\n[![Build Status](https://scrutinizer-ci.com/g/ericsizemore/simple_tpl/badges/build.png?b=master)](https://scrutinizer-ci.com/g/ericsizemore/simple_tpl/build-status/master)\n[![Code Coverage](https://scrutinizer-ci.com/g/ericsizemore/simple_tpl/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/ericsizemore/simple_tpl/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ericsizemore/simple_tpl/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ericsizemore/simple_tpl/?branch=master)\n[![Continuous Integration](https://github.com/ericsizemore/simple_tpl/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/ericsizemore/simple_tpl/actions/workflows/continuous-integration.yml)\n[![Type Coverage](https://shepherd.dev/github/ericsizemore/simple_tpl/coverage.svg)](https://shepherd.dev/github/ericsizemore/simple_tpl)\n[![Psalm Level](https://shepherd.dev/github/ericsizemore/simple_tpl/level.svg)](https://shepherd.dev/github/ericsizemore/simple_tpl)\n[![Latest Stable Version](https://img.shields.io/packagist/v/esi/simple_tpl.svg?label=stable)](https://packagist.org/packages/esi/simple_tpl)\n[![Development Version](https://img.shields.io/badge/dynamic/yaml?url=https%3A%2F%2Fgithub.com%2Fericsizemore%2Fsimple_tpl%2Fraw%2Fmaster%2Fcomposer.json\u0026query=%24%5B'extra'%5D%5B'branch-alias'%5D%5B'dev-master'%5D\u0026label=unstable\u0026color=%23ff4c00)](https://github.com/ericsizemore/simple_tpl/tree/master)\n[![Downloads per Month](https://img.shields.io/packagist/dm/esi/simple_tpl.svg)](https://packagist.org/packages/esi/simple_tpl)\n\u003c!-- Remove until 3.x release\n[![License](https://img.shields.io/packagist/l/esi/simple_tpl.svg)](https://packagist.org/packages/esi/simple_tpl)\n--\u003e\n\n[Simple Template Engine](http://github.com/ericsizemore/simple_tpl/) is a small, simple text-based template parsing engine that works on text replacement.\n\n\u003e [!IMPORTANT]\n\u003e The `master` branch currently holds the work-in-progress version `3.x`, which is a break from the backward compatibility promise.\n\u003e This will be resolved once `3.0.0` is released. Since `3.x` is under development, it is not recommended to use in a production environment.\n\u003e The public API, implementations, etc., can (and will likely) change.\n\n---\n\n## Installation\n\nCompatible with PHP \u003e= 8.2 and can be installed with [Composer](https://getcomposer.org).\n\n```bash\n$ composer require esi/simple_tpl:^3.0\n```\n\n## Usage\n\n### Storage\n\nThere are two storage implementations available: `Storage\\FilesystemStorage` and `Storage\\DatabaseStorage`.\nBoth storage implementations implement the `Storage\\StorageInterface` interface, with only one defined method: `loadTemplate()`.\n\n**NOTE:** If you wish to have a system for editing/saving, deleting or updating the templates themselves, you would need to implement this on your own.\nThis library only searches for templates that have already been created, by name, then parses them with a `key =\u003e value` associative array of variables.\n\n#### Filesystem Storage\n\nThe `FilesystemStorage` implementation allows you to use regular files for your templates.\nYour template files are expected to end with the `.tpl` extension. I plan to allow the ability to use different extensions later.\n\n1. Create a `FilesystemStorage` instance with the path/directory to where your templates are located.\n2. Pass this instance to the `Template` class when creating it.\n\nLet's say you had a template called `example_template.tpl` within the `./templates/` directory.\n\nTemplate file:\n```html\n\u003c!DOCTYPE HTML\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta http-equiv=\"content-type\" content=\"text/html\" /\u003e\n    \u003ctitle\u003e{title}\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cp\u003e{content}\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nPHP to parse the template:\n```php\nuse Esi\\SimpleTpl\\Template;\nuse Esi\\SimpleTpl\\Storage\\FilesystemStorage;\n\n$templateStorage = new FilesystemStorage('./templates/');\n$template = new Template($templateStorage);\n\n$template-\u003esetTplVars([\n    'title' =\u003e 'Hello, World!',\n    'content' =\u003e 'This is a simple template engine.'\n]);\n\necho $template-\u003eparse('example_template');\n```\n\nWhen calling `display()` or `parse()`, you only need to provide the file name without extension.\nFor example, if your template file is `mytemplate.tpl`, you would call either of these methods with `mytemplate`.\n\n#### Database Storage\n\nThe `DatabaseStorage` implementation allows you to use a database for your templates.\n\n1. Create a `PDO` instance with your database details to create a connection.\n2. Create a `DatabaseStorageConfig` with your template tables `tableName`, `nameField`, and `contentField`.\n3. Create a `DatabaseStorage` instance and pass the `PDO` and `DatabaseStorageConfig` instances to it.\n4. Pass the `DatabaseStorage` instance to the `Template` class when creating it.\n\nLet's say the content of the `example_template` is the same as in the [filesystem example](#filesystem-storage), and your\ndatabase table structure is:\n\n```sql\nCREATE TABLE IF NOT EXISTS `templates` (\n    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n    `name` VARCHAR(255) NOT NULL,\n    `content` MEDIUMTEXT NOT NULL,\n    PRIMARY KEY (`id`),\n    UNIQUE KEY `name` (`name`)\n)\n```\n\nThen your code would look something like:\n\n```php\nuse Esi\\SimpleTpl\\Template;\nuse Esi\\SimpleTpl\\Storage\\DatabaseStorage;\nuse Esi\\SimpleTpl\\Storage\\DatabaseStorageConfig;\nuse PDO;\n\n$pdo = new PDO('mysql:host=localhost;dbname=templates', 'user', 'password');\n$storageConfig = new DatabaseStorageConfig(); // with the example table structure above, the config defaults to 'templates', 'name', 'content'\n$templateStorage = new DatabaseTemplateStorage($pdo, $storageConfig);\n$template = new Template($templateStorage);\n\n$template-\u003esetTplVars([\n    'title' =\u003e 'Hello, World!',\n    'content' =\u003e 'This is a simple template engine.'\n]);\n\necho $template-\u003eparse('example_template');\n```\n\n### Caching\n\nIf you would like to utilize caching for templates, you will need to provide the library a [PSR-6](https://www.php-fig.org/psr/psr-6/) cache implementation.\nYou can view a list of packages that provide this implementation on [Packagist](https://packagist.org/providers/psr/cache-implementation).\n\nWhether you use `FilesystemStorage` or `DatabaseStorage`, you can use caching for either by passing an object that implements `\\Psr\\Cache\\CacheItemPoolInterface`.\n\nFor example:\n\n```bash\n$ composer require symfony/cache:^7.2 \n```\n\n```php\nuse Esi\\SimpleTpl\\Template;\nuse Esi\\SimpleTpl\\Storage\\FilesystemStorage;\nuse Symfony\\Component\\Cache\\Adapter\\AbstractAdapter;\n\n$templateStorage = new FilesystemStorage('/path/to/templates');\n$template = new Template(\n    $templateStorage,\n    /**\n     * Symfony's AbstractAdapter::createSystemCache() returns the best possible adapter that your runtime supports.\n     * Generally, it will create a cache via PHP files (Opcache must be enabled via opcache.enable in php.ini), and chain that with APCu if your system supports it.\n     *\n     * For more information on symfony/cache's available cache pool (PSR-6) adapters:\n     * @see https://symfony.com/doc/current/components/cache/cache_pools.html \n     */\n    AbstractAdapter::createSystemCache(namespace: 'simple_tpl', defaultLifetime: 300, version: '', directory: sys_get_temp_dir())\n);\n\n// ... assign vars, parse /display template, etc ...\n```\n\n## About\n\n### Requirements\n\n- SimpleTpl works with PHP 8.2.0 or above.\n\n## Credits\n\n- Author: [Eric Sizemore](https://github.com/ericsizemore)\n- Thanks to [all Contributors](https://github.com/ericsizemore/simple_tpl/contributors).\n\n## Contributing\n\nSee [CONTRIBUTING](./CONTRIBUTING.md) for more information.\n\nBugs and feature requests are tracked on [GitHub](https://github.com/ericsizemore/simple_tpl/issues).\n\n### Contributor Covenant Code of Conduct\n\nSee [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md)\n\n### Backward Compatibility Promise\n\nSee [backward-compatibility.md](./backward-compatibility.md) for more information on Backwards Compatibility.\n\n### Changelog\n\nSee the [CHANGELOG](./CHANGELOG.md) for more information on what has changed recently.\n\n### License\n\nSimple Template Engine's license depends on the version you are using:\n\n* `v3.0.0` and later is licensed under `The MIT License`.\n* `v2.0.1` and earlier is licensed under the [`GNU GPL v3 License`](https://github.com/ericsizemore/simple_tpl/blob/2.x/LICENSE).\n\nSee the [LICENSE](./LICENSE.md) for more information on the license that applies to this project.\n\n### Security\n\nSee [SECURITY](./SECURITY.md) for more information on the security disclosure process.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericsizemore%2Fsimple_tpl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericsizemore%2Fsimple_tpl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericsizemore%2Fsimple_tpl/lists"}