{"id":23141722,"url":"https://github.com/minicli/stencil","last_synced_at":"2025-08-17T13:32:00.101Z","repository":{"id":37408896,"uuid":"505419279","full_name":"minicli/stencil","owner":"minicli","description":"A dummy template generator","archived":false,"fork":false,"pushed_at":"2023-07-13T13:45:23.000Z","size":36,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-20T01:40:18.459Z","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/minicli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-20T11:49:20.000Z","updated_at":"2022-06-21T23:28:19.000Z","dependencies_parsed_at":"2022-08-18T18:40:58.349Z","dependency_job_id":null,"html_url":"https://github.com/minicli/stencil","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minicli%2Fstencil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minicli%2Fstencil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minicli%2Fstencil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minicli%2Fstencil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/minicli","download_url":"https://codeload.github.com/minicli/stencil/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230128408,"owners_count":18177599,"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":"2024-12-17T14:14:16.726Z","updated_at":"2024-12-17T14:14:17.426Z","avatar_url":"https://github.com/minicli.png","language":"PHP","readme":"# Stencil\n\n\u003e **/ˈstɛns(ə)l/** (noun): \na thin sheet of card, plastic, or metal with a pattern or letters cut out of it, used to produce the cut design on the surface below by the application of ink or paint through the holes.\n\n**Minicli/Stencil** is a dummy content replacer useful for generating templates. \n\nStencils are like lightweight templates with no advanced functionality (so it's not an engine). It simply replaces placeholders with content set up in a string-indexed array or dictionary.\n\nIf you are looking for a templating system for front-end views, this is not it! Go check [Twig](https://twig.symfony.com/). Stencil is useful for generating skeleton content (such as to auto-generate classes, Markdown docs and other files following a certain structure).\n\n## Dependencies\nStencil is a tiny standalone library that has only testing dependencies.\n\n## Usage\n\n### Within Minicli\nIf you want to use Stencil within a Minicli app, you should have a look at the [Minicli Stencil command](https://github.com/minicli/command-stencil) that contains a basic implementation of a command using Stencil to generate documents based on templates. Check that repo for usage instructions.\n\n### Standalone\nFor more freedom to include Stencil on your codebase, install standalone Stencil via Composer:\n\n```shell\ncomposer require minicli/stencil\n```\n\nSet up a directory within your project to hold your stencils:\n\n```shell\nmkdir stencils\ncd stencils\n```\n\nCreate a new `.tpl` file with some variables:\n\n```shell\n#stencils/mytemplate.tpl\n\n## This is my Template\n\nMy name is {{ name }} and I am a {{ description }}.\n```\n\nFrom your project, instantiate a new Stencil, passing along the stencils directory you set up. Then, call the `applyTemplate` method with an array containing your values:\n\n```php\n\u003c?php\n\n$stencil = new Stencil(__DIR__ . '/stencils');\n\n$values = [\n    'name' =\u003e 'Stencil',\n    'description' =\u003e 'minimalist, dummy template generator.'\n];\n\n$parsedContent = $stencil-\u003eapplyTemplate('mytemplate', $values);\nvar_dump($parsedContent);\n```\n```shell\nstring(92) \"## This is my Template\n\nMy name is Stencil and I am a minimalist, dummy template generator..\"\n```\n\n## Querying templates for variables\n\nYou can also obtain the variables set within a template in order to build your array of values in a step-by-step way, such as interactively via command-line prompts.\n\nThis is an example code that collects variables from a Stencil template and then prompts users for each variable found, returning an array that can then be used with `$stencil-\u003eapplyTemplate()`:\n\n```php\n\n$stencil = new Stencil(__DIR__ . '/stencils');\n$template = 'mytemplate';\n$values = [];\n$variables = $stencil-\u003escanTemplateVars($template);\n\necho \"Building template $template\\n\";\nforeach ($variables as $variable) {\n    echo ucfirst($variable);\n    $values[$variable] = readline(': ');\n}\n\necho $stencil-\u003eapplyTemplate($template, $values);\n\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminicli%2Fstencil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fminicli%2Fstencil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminicli%2Fstencil/lists"}