{"id":25326389,"url":"https://github.com/beastbytes/view-latte","last_synced_at":"2026-03-16T20:04:39.229Z","repository":{"id":274881009,"uuid":"924381585","full_name":"beastbytes/view-latte","owner":"beastbytes","description":"Yii View Latte Renderer","archived":false,"fork":false,"pushed_at":"2025-06-01T20:30:37.000Z","size":188,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-02T06:18:05.481Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beastbytes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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,"zenodo":null}},"created_at":"2025-01-29T22:30:47.000Z","updated_at":"2025-06-01T20:30:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"b8e0676c-8b0c-4b67-ad2d-0168d6efaa95","html_url":"https://github.com/beastbytes/view-latte","commit_stats":null,"previous_names":["beastbytes/view-latte"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/beastbytes/view-latte","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beastbytes%2Fview-latte","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beastbytes%2Fview-latte/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beastbytes%2Fview-latte/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beastbytes%2Fview-latte/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beastbytes","download_url":"https://codeload.github.com/beastbytes/view-latte/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beastbytes%2Fview-latte/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259293098,"owners_count":22835539,"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-02-14T01:42:52.248Z","updated_at":"2026-03-16T20:04:39.185Z","avatar_url":"https://github.com/beastbytes.png","language":"PHP","readme":"This package is an extension of the [Yii View Rendering Library](https://github.com/yiisoft/view/). This extension\nprovides a `ViewRender` that allows use of the [Latte](https://latte.nette.org/) view template engine.\n\n`Latte` has some advantages over `Twig` as a templating engine:\n* The major advantage of Latte is that it is PHP (Twig is Python), this makes writing Latte templates simpler\nand debugging them (if you need to) a lot simpler.\n* Use [PHP expressions in templates](https://latte.nette.org/en/syntax#toc-latte-understands-php) \n* Better defence against XSS (Cross Site Scripting)\n* Excellent plugin for PhpStorm that enables type hints, code completion, etc.\n\n## Requirements\n- PHP 8.1 or higher.\n\n## Installation\nInstall the package using [Composer](https://getcomposer.org):\n\nEither:\n```shell\ncomposer require beastbytes/view-latte\n```\nor add the following to the `require` section of your `composer.json`\n```json\n\"beastbytes/view-latte\": \"*\"\n```\n\n## Configuration\nIn order to register `Latte` as the renderer in `WebView`, the `beastbytes/view-latte` package must override \nthe `yiisoft\\view` package configuration. To do this, add `beastbytes/view-latte` to the `vendor-override-layer`\noption in `config-plugin-options`; this is either in the `extra` section of your root `composer.json`\nor in your external configuration file.\n\n### composer.json\n```json\n\"extra\": {\n    \"config-plugin-options\": {\n        \"vendor-override-layer\": [\n          \"beastbytes/view-latte\"\n        ]\n    },\n    \"config-plugin\": {\n        // ...\n    }\n}\n```\n### External Configuration File\n```php\n'config-plugin-options' =\u003e [\n    // other config-plugin-options\n    'vendor-override-layer' =\u003e [\n        'beastbytes/view-latte',\n        // other vendor overrides\n    ]    \n],\n```\n_Note:_ if `beastbytes/view-latte` is the only vendor override,\nit can be specified as a string in both of the configuration formats.\n\n### Params\nThe `beastbytes/view-latte` package supports the addition of user defined filters, functions, and extensions to `Latte`.\nEach filter and function is defined in its own class; extensions are packages.\n\nTo add them to `Latte` specify them in the `filterProviders`, `functionProviders`, and `extensions` keys\nof `beastbytes/view-latte` in the `params` array.\n\n```php\n'beastbytes/view-latte' =\u003e [\n    'filterProviders' =\u003e [\n        new MyLatteFilter()\n    ],\n    'functionProviders' =\u003e [\n        new MyLatteFunction()\n    ],\n    'extensions' =\u003e [\n        new myLatteExtension()\n    ]\n],\n```\n\nSee [User Defined Filters and Functions](#user-defined-filters-and-functions) \nfor details on how to define filters and functions.\n\nSee [Creating an Extension](https://latte.nette.org/en/creating-extension) for details on how to create an extension.\n\n## Templates\nAs you would expect, all the variables defined when calling the view renderer's `render()` method in an action are\navailable in the template, as are injected variables.\n\nThe Latte extension provides access to everything defined in the application container \nin all view templates and layouts.\n\n#### Basic Layout \u0026 View Templates\n**Note:** A major difference between `Latte` and `PHP` templates is the definition of `$this`.\n* `$this` in Latte templates is the Latte template being rendered\n* `$view` is the WebView instance\n\n```latte\n{varType string $content}\n{varType Yiisoft\\View\\WebView $view}\n\n{do $assetManager-\u003eregister('App\\Asset\\AppAsset')}\n{do $view-\u003eaddCssFiles($assetManager-\u003egetCssFiles())}\n{do $view-\u003eaddCssStrings($assetManager-\u003egetCssStrings())}\n{do $view-\u003eaddJsFiles($assetManager-\u003egetJsFiles())}\n{do $view-\u003eaddJsStrings($assetManager-\u003egetJsStrings())}\n{do $view-\u003eaddJsVars($assetManager-\u003egetJsVars())}\n\n{$view-\u003ebeginPage()|noescape}\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"\"\u003e\n    \u003chead\u003e\n        \u003cmeta charset=\"utf-8\"\u003e\n        \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"\u003e\n        \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n        \u003ctitle\u003e{$view-\u003egetTitle()}\u003c/title\u003e\n        {$view-\u003ehead()|noescape}\n    \u003c/head\u003e\n    \u003cbody\u003e\n        {$view-\u003ebeginBody()|noescape}\n        {include 'header.latte'}\n        \u003cmain role=\"main\" class=\"container py-4\"\u003e\n            {$content|noescape}\n        \u003c/main\u003e\n        {include 'footer.latte'}\n        {$view-\u003eendBody()|noescape}\n    \u003c/body\u003e\n\u003c/html\u003e\n{$view-\u003eendPage(true)|noescape}\n```\n\nAnd a view template will be:\n```latte\n{varType App\\ApplicationParameters $applicationParameters}\n{varType Yiisoft\\View\\WebView $view}\n\n{do $view-\u003esetTitle($applicationParameters-\u003egetName())}\n\n\u003ch1 class=\"title\"\u003eHello!\u003c/h1\u003e\n\n\u003cp class=\"subtitle\"\u003eLet's start something great with \u003cstrong\u003eYii3 \u0026amp; Latte\u003c/strong\u003e!\u003c/p\u003e\n\n\u003cp class=\"subtitle is-italic\"\u003e\n    \u003ca href=\"https://github.com/yiisoft/docs/tree/master/guide/en\" target=\"_blank\" rel=\"noopener\"\u003e\n        Don't forget to check the Yii guide \n    \u003c/a\u003e\n    \u003ca href=\"https://latte.nette.org/en/guide\" target=\"_blank\" rel=\"noopener\"\u003e\n        and the Latte documentation.\n    \u003c/a\u003e    \n\u003c/p\u003e\n```\n\n## View-Latte Extensions\nThe `view-latte` package contains the following extensions:\n\n### CacheExtension\n**NOTE: CacheExtension is not implemented yet**\n\nThe `CacheExtension` allows caching of view fragments and dynamic content within cached fragments.\nThe extension provides the `cache` and `dynamic` tags.\nIt is enabled if the DI container contains a `Yiisoft\\Cache\\CacheInterface` implementation.\n\n**NOTE:** Templates using caching _must_ have the variable `$cache`,\na concrete instance of  `Yiisoft\\Cache\\CacheInterface`, defined\n```latte\n{varType Yiisoft\\Cache\\CacheInterface $cache}\n```\n\n#### {cache} Tag\nThe `cache` tag allows a template or part of a template to be cached. The tag has three parameters:\n* ttl (int) \u0026ndash; The TTL of the cached content in seconds. Default is `60`.\n* dependency (Yiisoft\\Cache\\Dependency\\Dependency|null) \u0026ndash; The dependency of the cached content. \nDefault is `null`.\n* beta (float) \u0026ndash; The value for calculating the range that's used for \"Probably early expiration\".\nDefault is `1.0`.\n\n##### Examples\n###### Basic Usage\n```latte\n{cache}\n    content to be cached\n{/cache}\n```\n###### Set TTL\n```latte\n{cache 3600}\ncontent to be cached\n{/cache}\n```\n###### Set a Dependency\n```latte\n{cache 3600, new Yiisoft\\Cache\\Dependency\\TagDependency('fragment-1')}\n    content to be cached\n{/cache}\n...\n{if $theAnswerToTheUltimateQuestionOfLife !== 42}\n    {do Yiisoft\\Cache\\Dependency\\TagDependency::invalidate('fragment-1')}\n{/if}\n```\n\n#### {dynamic} Tag\nThe `dynamic` tag defines dynamic content within a `cache` tag. The tag has three parameters:\n* contentGenerator (callable) \u0026ndash; a callable that generates the dynamic content;\nit has the signature `function (array $parameters = []): string;`\n* parameters (array) \u0026ndash; parameters as key=\u003evalue pairs passed to contentGenerator\n```latte\n{dynamic function (array $parameters = []): string {return $generatedContent}, ['a' =\u003e 1, 'b' =\u003e 2]}\n```\n\nThere is no limit to the number of `dynamic` tags within a `cache` tag.\n\n### UrlExtension\nThe `UrlExtension` allows generation of URL using routes.\nThe extension provides the `n:action`, `n:href`, and `n:src` n:attributes and `link` tag to generate URLs.\nIt is enabled if the DI container contains a `Yiisoft\\Router\\UrlGeneratorInterface` implementation.\n\n#### n:attributes\nThe `n:action`, `n:href`, and `n:src` n:attributes are used to generate URLs as attributes in HTML tags;\ntheir parameters are the same as `Yiisoft\\Router\\UrlGeneratorInterface::generate().\n\n##### n:action Attribute\nThe `n:action` attribute is used to generate the action URL in `\u003cform/\u003e` tags.\n```latte\n\u003cform n:action=\"route/name, arguments, queryParameters\"\u003e\n    // Form controls\n\u003c/form\u003e\n```\n\n**Tip** The [form-latte extension](https://github.com/beastbytes/form-latte) \nintegrates the Yii Framework Form package with view-latte.\n\n##### n:href Attribute\nThe `n:href` attribute is used to generate links in `\u003ca/\u003e` tags;\n```latte\n\u003ca n:href=\"route/name, arguments, queryParameters\"\u003eContent\u003c/a\u003e\n```\n\n##### n:src Attribute\nThe `n:src` attribute is used to generate URLs to the media source in media tags, e.g. `\u003cimg/\u003e`;\n```latte\n\u003cimg n:src=\"route/name, arguments, queryParameters\"/\u003e\n```\n\n#### {link} Tag\nThe `{link}` tag is used to print a URL;\nits parameters are the same as `Yiisoft\\Router\\UrlGeneratorInterface::generate().\n```latte\n{link route/name, arguments, queryParameters}\n```\n\n### UseExtension\nThe `UseExtension` emulates PHP's `use` operator and allows writing cleaner templates.\nThe extension provides provides the `use` tag.\nIt is always enabled.\n\nBy default, Latte templates require the use of Fully Qualified CLass Names (FQCN); this can lead to cluttered templates.\nThe `use` tag emulates PHP's `use` operator and allows templates to define the FQCN and optionally an alias,\nand refer to the _used_ class by the alias or base class name.\n\n#### Using Namespaced Classes in Latte\nThe FQCN must be defined in a `use` tag before the base class name or alias is referenced in the template.\nThe best way to ensure this is to place `use` tags at the start of the template.\n\nThe extension replaces the alias or base class name defined in the `use` tag with the FQCN in class instantation (`new`)\nstatements and class constants during compilation; it _does not_ import or alias the class.\n\n#### Differences from PHP\n* There is no `as` clause when defining an alias\n* Group `use` definitions are _not_ supported.\n\n#### {use} Tag\n```latte\n{use Framework\\Module\\NamespacedClass}\n\n\u003cp\u003eThe value is {(new NamespacedClass)-\u003egetValue()}\u003c/p\u003e\n\u003cp\u003eThe constant is {NamespacedClass::CONSTANT}\u003c/p\u003e\n```\n\n#### {use} Tag with Alias\n```latte\n{use Framework\\Module\\Aliased\\NamespacedClass AliasedClass}\n\n\u003cp\u003eThe value is {(new AliasedClass)-\u003egetValue()}\u003c/p\u003e\n\u003cp\u003eThe constant is {AliasedClass::CONSTANT}\u003c/p\u003e\n```\n\n#### Multiple {use} Tags\n```latte\n{use Framework\\Module\\Aliased\\NamespacedClass AliasedClass}\n{use Framework\\Module\\NamespacedClass}\n\n{varType int $arg}\n{varType string $testString}\n\n\u003cp\u003eThe value is {(new NamespacedClass($arg))-\u003egetValue()}\u003c/p\u003e\n\u003cp\u003eThe constant is {NamespacedClass::CONSTANT}\u003c/p\u003e\n\u003cp\u003e{$testString|replace: AliasedClass::CONSTANT}\u003c/p\u003e\n```\n\n### YiiLatteExtension\nThe `YiiLatteExtension` allows access to any package in the DI container.\nThe extension provides the `get` function which takes the id of the required package as a parameter.\nIt is always enabled.\n\n#### get() Function\n```latte\n{do $package = get('PackageId')}\n```\n\n## Other Extensions\n### TranslatorExtension\nLatte's Translation Extension is enabled if \nthe DI container contains a `Yiisoft\\Translator\\TranslatorInterface` implementation, \nallowing use of Latte's Translation [tags](https://latte.nette.org/en/tags#toc-translation)\nand [filter](https://latte.nette.org/en/filters#toc-translate) in templates.\n\n### RawPhpExtension\nLatte's `RawPhpExtension` is _not_ enabled by default. To enable it, add it to the `extensions` section\nof the `beastbytes/view-latte` in your configuration parameters:\n\n```php\nreturn [\n    'beastbytes/view-latte' =\u003e [\n        'extensions' =\u003e [\n            new \\Latte\\Essential\\RawPhpExtension(),\n            // Other extensions\n        ],\n        // Other view-latte configuration\n    ],\n]\n```\n\n## User Defined Filters and Functions\nThe `view-latte` package supports the addition of user-defined filters and functions to the Latte Engine;\nsee [Configuration -\u003e Params](#params) for details on how to specify them. This section details how to define them.\n\nEach filter and/or function is defined in its own class. Filters must implement the FilterProviderinterface\nand functions the FunctionProviderinterface; both **_must_** implement the `__invoke()` method to provide their\nfunctionality.\n\n### Example Filter\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Latte\\Providers;\n\nuse BeastBytes\\View\\Latte\\Provider\\FilterProvider;\n\nclass MyLatteFilter implements FilterProvider\n{\n    public function getName(): string\n    {\n        return 'myLatteFilter'; // the name registered with Latte and used to invoke the filter in templates\n    }\n\n    public function __invoke(string $string): string\n    {\n        return strrev($string);\n    }\n}\n```\n\n### Example Function\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Latte\\Providers;\n\nuse BeastBytes\\View\\Latte\\Provider\\FunctionProvider;\n\nclass MyLatteFunction implements FunctionProvider\n{\n    public function getName(): string\n    {\n        return 'myLatteFunction'; // the name registered with Latte and used to call the function in templates\n    }\n\n    public function __invoke(int $number): int\n    {\n        return $number * 2;\n    }\n}\n```\n\n### Example Template\n```latte\n{var int $x = 2}\n{var string $strig = 'ABCDE'}\n\n\u003cp\u003e{$strig|myLatteFilter}\u003c/p\u003e \u003c!-- will output EDCBA --\u003e\n\u003cp\u003e{=myLatteFunction($x)}\u003c/p\u003e \u003c!-- will output 4 --\u003e\n```\n\n## License\nThe BeastBytes View Latte Renderer is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeastbytes%2Fview-latte","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeastbytes%2Fview-latte","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeastbytes%2Fview-latte/lists"}