{"id":24764084,"url":"https://github.com/stillat/statamic-template-resolver","last_synced_at":"2025-06-21T18:05:00.289Z","repository":{"id":205509545,"uuid":"714395317","full_name":"Stillat/statamic-template-resolver","owner":"Stillat","description":"Provides utilities to resolve templates based on an entry's collection or blueprint handles, with support for a fallback template.","archived":false,"fork":false,"pushed_at":"2024-05-11T20:10:09.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-02T16:30:08.112Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Stillat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"JohnathonKoster"}},"created_at":"2023-11-04T19:28:02.000Z","updated_at":"2024-05-11T20:09:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"3a2e9395-ae8a-41dd-9d11-2fcdcffa73bb","html_url":"https://github.com/Stillat/statamic-template-resolver","commit_stats":null,"previous_names":["stillat/statamic-template-resolver"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Stillat/statamic-template-resolver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-template-resolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-template-resolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-template-resolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-template-resolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Stillat","download_url":"https://codeload.github.com/Stillat/statamic-template-resolver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Stillat%2Fstatamic-template-resolver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261170422,"owners_count":23119512,"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-01-28T21:32:34.239Z","updated_at":"2025-06-21T18:04:55.271Z","avatar_url":"https://github.com/Stillat.png","language":"PHP","funding_links":["https://github.com/sponsors/JohnathonKoster"],"categories":[],"sub_categories":[],"readme":"# Template Resolver for Statamic\n\nTemplate Resolver for Statamic is a simple utility addon, intended to be used by other addons. It provides a simple utility for selecting and rendering a template based on an entry's *blueprint* and *collection*, with support for a fallback default template.\n\nExample use-cases:\n\n* Selecting templates dynamically to generate social media images from HTML,\n* Generating HTML documents on-the-fly, without requiring network requests to the site,\n* Anything where you need to support customizable templates based on an entry's blueprint/collection details\n\n## How to Install\n\nRun the following command from your project root:\n\n``` bash\ncomposer require stillat/statamic-template-resolver\n```\n\n## How to Use\n\nYou need to create an instance of `StringTemplateManager`, and supply the directory to search for templates in.\n\n```php\n\u003c?php\n\nuse Stillat\\StatamicTemplateResolver\\StringTemplateManager;\n\n$manager = new StringTemplateManager(\n    resource_path('views/social_media_images')\n);\n```\n\nOnce you have a `StringTemplateManager` instance, you can check if a template exists for a given collection/blueprint combination:\n\n```php\n\u003c?php\n\n// ...\n\nif ($manager-\u003ehasTemplate($collection, $blueprint)) {\n    // The template exists.\n}\n\n```\n\nThe `hasTemplate` method will return `true` if a specific template *or* the default template exists. To create a default template, create a file named `_default.antlers.html` or `_default.blade.php` at the root of the template folder.\n\nIn our example, the default template would need to be placed here:\n\n```\nviews/social_media_images/_default.antlers.html\n```\n\nSpecific collection/blueprint templates are stored within a nested directory structure using the following format:\n\n```\n\u003ctemplate_directory\u003e\u003ccollection_handle\u003e/\u003cblueprint_handle\u003e.\u003cextension\u003e\n```\n\nFor example, if we had a `blog` collection, with a `post` blueprint, we could create a specific template at the following location:\n\n```\nviews/social_media_images/blog/post.antlers.html\n```\n\nThis library supports the following extensions:\n\n* `.antlers.html`: Renders the template using Statamic's Antlers templating engine\n* `.blade.php`: Renders the template using Laravel's Blade templating engine\n\nTo render a template with data, we may use the `render` method:\n\n```php\n\u003c?php\n\n// ...\n\n$results = $manager-\u003erender(\n    'colllection_handle',\n    'blueprint_handle',\n    $data\n);\n\n```\n\nThe `render` method will return `null` if a template could not be found; `$data` is provided as an array, and is required.\n\nWe may also optionally modify the template before rendering it by supplying an optional callable as the fourth argument:\n\n```php\n\u003c?php\n\n// Modify the template before its rendered.\n$results = $manager-\u003erender(\n    'collection_handle',\n    'blueprint_handle',\n    $data,\n    function ($template, $data) {\n        return mb_strtoupper($template);\n    }\n);\n\n```\n\nThe modifying callable will receive the unmodified template contents as its first argument, and the original data array as the second.\n\n## License\n\nStatamic Template Resolver is free software, released under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstillat%2Fstatamic-template-resolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstillat%2Fstatamic-template-resolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstillat%2Fstatamic-template-resolver/lists"}