### Install Plates with Composer Command Source: https://github.com/thephpleague/plates/blob/v3/doc/content/getting-started/installation.md This command installs the Plates templating engine into your PHP project using Composer. It fetches the latest compatible version of Plates and its dependencies from Packagist, making them available for use. Requires Composer to be installed and accessible in your system's PATH. ```bash composer require league/plates ``` -------------------------------- ### Define Plates Dependency in composer.json Source: https://github.com/thephpleague/plates/blob/v3/doc/content/getting-started/installation.md This JSON snippet specifies Plates as a project dependency within your composer.json file, requesting any version from the 3.x series. After adding this, run composer install or composer update to download the library. This method ensures version control and dependency management. ```javascript { "require": { "league/plates": "3.*" } } ``` -------------------------------- ### PHP Plates Template Syntax Example Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/syntax.md This snippet demonstrates the recommended syntax guidelines for PHP Plates templates, including layout definition, variable escaping, alternative control structures, and conditional rendering. It shows how to display user information, loop through friends, and conditionally show invitations. This example requires the Plates templating engine. ```PHP layout('template', ['title' => 'User Profile']) ?>

Welcome!

Hello e($name)?>

Friends

Invitations

You have some friend invites!

``` -------------------------------- ### Plates URI Extension `uri()` Function Usage Examples Source: https://github.com/thephpleague/plates/blob/v3/doc/content/extensions/uri.md These PHP snippets demonstrate various ways to use the `uri()` function provided by the Plates URI extension. Examples include retrieving the full URI, getting specific segments, checking segment equality, and matching regular expressions, with options for returning different values based on success or failure. ```php uri()?> ``` ```php uri(1)?> ``` ```php uri(1, 'home')): ?> ``` ```php uri(1, 'home', 'success')?> ``` ```php uri(1, 'home', 'success', 'fail')?> ``` ```php uri('/home')): ?> ``` ```php uri('/home', 'success')?> ``` ```php uri('/home', 'success', 'fail')?> ``` -------------------------------- ### Initialize & Render Plates in PHP Controller Source: https://github.com/thephpleague/plates/blob/v3/doc/content/getting-started/simple-example.md This PHP snippet demonstrates how to create a new Plates engine instance, specifying the path to your templates. It then shows how to render a specific template, passing an associative array of data that will be available within the template scope. ```php // Create new Plates instance $templates = new League\Plates\Engine('/path/to/templates'); // Render a template echo $templates->render('profile', ['name' => 'Jonathan']); ``` -------------------------------- ### Basic Usage of Plates Engine Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/overview.md This snippet demonstrates the fundamental steps to initialize and configure the Plates templating engine. It covers creating an engine instance, adding template folders, loading extensions, and creating a new template object. This setup is essential for any Plates-based project. ```php // Create new Plates engine $templates = new League\Plates\Engine('/path/to/templates'); // Add any additional folders $templates->addFolder('emails', '/path/to/emails'); // Load any additional extensions $templates->loadExtension(new League\Plates\Extension\Asset('/path/to/public')); // Create a new template $template = $templates->make('emails::welcome'); ``` -------------------------------- ### Serve Plates Documentation Locally with Hugo Source: https://github.com/thephpleague/plates/blob/v3/CONTRIBUTING.md This command allows you to serve the Plates project documentation locally using Hugo. It requires Hugo version 0.79 or later to be installed on your system. ```bash hugo -s doc server ``` -------------------------------- ### Install Plates PHP Template System via Composer Source: https://github.com/thephpleague/plates/blob/v3/README.md This snippet shows how to install the Plates native PHP template system using Composer. Composer is a dependency manager for PHP, which will download and manage the Plates library and its dependencies. Run this command in your project's root directory to add Plates to your project. ```bash composer require league/plates ``` -------------------------------- ### PHP Plates: Get Template Path with path() Method Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/overview.md This example illustrates how to retrieve the file path of a template using the Plates engine's `path()` method. It also demonstrates how to get the path from an existing template object. This functionality is useful for debugging or when direct file access is required. ```PHP $path = $templates->path('articles::beginners_guide'); $path = $template->path(); ``` -------------------------------- ### PHP Plates: Manually Create and Render Template Objects Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/overview.md This example illustrates how to manually instantiate a `League\Plates\Template\Template` object. It shows rendering the template using its `render()` method and also via the `toString()` magic method. This approach offers more granular control over template instances. ```PHP // Create new Plates instance $templates = new League\Plates\Engine('/path/to/templates'); // Create a new template $template = new League\Plates\Template\Template($templates, 'profile'); // Render the template echo $template->render(['name' => 'Jonathan']); // You can also render the template using the toString() magic method echo $template; ``` -------------------------------- ### PHP Plates: Create Content Sections with start() and stop() Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/sections.md This snippet demonstrates how to define a content section in a Plates template. The `start()` function initiates a section with a given name, and the `stop()` function concludes it, saving the enclosed content for later rendering, typically in a layout. ```PHP start('welcome') ?>

Welcome!

Hello e($name)?>

stop() ?> ``` -------------------------------- ### Run PHPUnit Tests for Plates Project Source: https://github.com/thephpleague/plates/blob/v3/CONTRIBUTING.md This snippet shows how to execute the PHPUnit test suite for the Plates project. Ensure PHPUnit is installed and configured correctly in your development environment. ```bash $ phpunit ``` -------------------------------- ### Plates PHP Page Template (profile.php) Source: https://github.com/thephpleague/plates/blob/v3/doc/content/getting-started/simple-example.md This PHP template (`profile.php`) illustrates how a content page uses the Plates layout feature. It extends a base layout template and displays dynamic data passed from the controller, demonstrating the use of `$this->e()` for HTML escaping. ```php layout('template', ['title' => 'User Profile']) ?>

User Profile

Hello, e($name)?>

``` -------------------------------- ### Install Plates URI Extension with PHP Source: https://github.com/thephpleague/plates/blob/v3/doc/content/extensions/uri.md This snippet demonstrates how to load the URI extension into a Plates engine instance. It shows two methods: using a global `$_SERVER['PATH_INFO']` variable or a `HttpFoundation` request object to provide the URI path, which is required for the extension's functionality. ```php // Load URI extension using global variable $engine->loadExtension(new League\Plates\Extension\URI($_SERVER['PATH_INFO'])); // Load URI extension using a HttpFoundation's request object $engine->loadExtension(new League\Plates\Extension\URI($request->getPathInfo())); ``` -------------------------------- ### PHP: Create Simple Plates Extension with Custom Functions Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/extensions.md This PHP snippet demonstrates creating a basic Plates extension by implementing `ExtensionInterface`. It registers `uppercase` and `lowercase` functions to transform strings, making them directly available in templates. The example includes PHP class definition and HTML usage examples. ```PHP use League\Plates\Engine; use League\Plates\Extension\ExtensionInterface; class ChangeCase implements ExtensionInterface { public function register(Engine $engine) { $engine->registerFunction('uppercase', [$this, 'uppercaseString']); $engine->registerFunction('lowercase', [$this, 'lowercaseString']); } public function uppercaseString($var) { return strtoupper($var); } public function lowercaseString($var) { return strtolower($var); } } ``` ```HTML

Hello, e($this->uppercase($name))?>

``` ```HTML

Hello e($name, 'uppercase')

``` -------------------------------- ### Initialize Plates Engine with Theme Hierarchy (PHP) Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/themes.md Demonstrates how to configure the Plates engine to use a theme hierarchy, defining parent and child theme directories for template resolution. This setup allows for a structured approach to template overrides. ```php use League\Plates\{Engine, Template\Theme}; $plates = Engine::fromTheme(Theme::hierarchy([ Theme::new('/templates/main', 'Main'), // parent Theme::new('/templates/user', 'User'), // child Theme::new('/templates/seasonal', 'Seasonal'), // child2 ])); ``` -------------------------------- ### PHP Plates: Applying Multiple Functions with batch() Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/functions.md Illustrates how to use the `batch()` function to apply a sequence of transformations to a variable, simplifying code compared to nested function calls. It shows examples with and without `batch()` for clarity, demonstrating its utility for chained operations. ```php

Welcome escape(strtoupper(strip_tags($name)))?>

Welcome batch($name, 'strip_tags|strtoupper|escape')?>

``` -------------------------------- ### Plates PHP Layout Template (template.php) Source: https://github.com/thephpleague/plates/blob/v3/doc/content/getting-started/simple-example.md This PHP template (`template.php`) serves as a Plates layout, defining the common structure for multiple pages. It shows how to include a dynamic title and how to define a section (`content`) where child templates can inject their specific content. ```php <?=$this->e($title)?> section('content')?> ``` -------------------------------- ### Dependency Injection with Plates Engine Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/overview.md This example illustrates how to inject the Plates Engine into a PHP class, such as a controller, for seamless integration. It shows two common patterns: creating a template object for later rendering and directly rendering a template. This approach promotes testability and modularity in your application. ```php class Controller { private $templates; public function __construct(League\Plates\Engine $templates) { $this->templates = $templates; } // Create a template object public function getIndex() { $template = $this->templates->make('home'); return $template->render(); } // Render a template directly public function getIndex() { return $this->templates->render('home'); } } ``` -------------------------------- ### Define PHP Plates Layout with Folders Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/layouts.md This example shows how to specify a layout template located within a defined folder using the `layout()` function. It allows for better organization of templates by grouping them into logical directories. ```PHP layout('shared::template') ?> ``` -------------------------------- ### PHP Plates: Understanding Batch Function Execution Order Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/functions.md Explains the left-to-right execution order of functions within `batch()`, and how it prioritizes extension functions over native PHP functions in case of naming conflicts. Provides examples demonstrating the impact of function order on the final output. ```php batch('Jonathan', 'escape|strtolower|strtoupper')?> batch('Jonathan', 'escape|strtoupper|strtolower')?> ``` -------------------------------- ### Run Plates PHP Test Suite with Composer Source: https://github.com/thephpleague/plates/blob/v3/README.md This snippet demonstrates how to execute the test suite for the Plates PHP template system using Composer. Composer scripts are often defined in 'composer.json' to simplify common development tasks like running tests. Ensure you have development dependencies installed before running this command. ```bash composer test ``` -------------------------------- ### Include Composer Autoload File in PHP Project Source: https://github.com/thephpleague/plates/blob/v3/doc/content/getting-started/installation.md This PHP line includes Composer's autoloader, which is crucial for automatically loading classes and dependencies managed by Composer. It should be placed early in your application's bootstrap process to ensure all required libraries are available. This eliminates the need for manual require or include statements for each class. ```php require 'vendor/autoload.php'; ``` -------------------------------- ### Define Blog Layout Extending Main Site Layout in PHP Plates Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/layouts.md This example shows a blog-specific layout that extends the main site layout using `layout('template')`. It defines a blog title, an article section for content, and an aside for a sidebar, demonstrating layout stacking. ```PHP layout('template', ['title' => $title]) ?>

The Blog

section('content')?>
``` -------------------------------- ### Install and Configure Plates Asset Extension in PHP Source: https://github.com/thephpleague/plates/blob/v3/doc/content/extensions/asset.md This snippet demonstrates how to load and configure the Plates Asset extension. It requires the file system path to your public assets directory and an optional boolean to enable filename caching instead of the default query string method. ```php // Load asset extension $engine->loadExtension(new League\Plates\Extension\Asset('/path/to/public/assets/', true)); ``` -------------------------------- ### Access Template Content in PHP Plates Layout Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/layouts.md This example demonstrates how a layout template accesses the rendered content of the implementing template. The `section('content')` function is used to embed all output from the child template that is not part of a named section. ```PHP <?=$this->e($title)?> section('content')?> ``` -------------------------------- ### PHP Plates: Implement Layout and Define Sections Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/inheritance.md This PHP code demonstrates how to implement a base template defined in Plates, specifically 'template.php'. It shows how to extend a layout using $this->layout(), pass data like 'title', and define content for specific sections ('page' and 'sidebar') using start() and stop() functions. This allows for dynamic page content within a predefined structure. ```PHP layout('template', ['title' => 'User Profile']) ?> start('page') ?>

Welcome!

Hello e($name)?>

stop() ?> start('sidebar') ?> stop() ?> ``` -------------------------------- ### Use Plates Asset Extension in HTML Templates Source: https://github.com/thephpleague/plates/blob/v3/doc/content/extensions/asset.md This example demonstrates how to integrate the Plates Asset extension within your HTML templates. By calling `$this->asset('/path/to/file.ext')`, the extension automatically generates the cache-busted URL, ensuring your templates always link to the correct asset version. ```html Asset Extension Example ``` -------------------------------- ### PHP: Implement Single-Method Plates Extension for Object Access Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/extensions.md This PHP example shows how to create a Plates extension that exposes its entire object via a single function, `case`. This approach improves template legibility and reduces naming conflicts, allowing access to methods like `upper` and `lower` through the exposed object. HTML usage is also provided. ```PHP use League\Plates\Engine; use League\Plates\Extension\ExtensionInterface; class ChangeCase implements ExtensionInterface { public function register(Engine $engine) { $engine->registerFunction('case', [$this, 'getObject']); } public function getObject() { return $this; } public function upper($var) { return strtoupper($var); } public function lower($var) { return strtolower($var); } } ``` ```HTML

Hello, e($this->case()->upper($name))?>

``` -------------------------------- ### Plates URI Extension HTML Menu Example Source: https://github.com/thephpleague/plates/blob/v3/doc/content/extensions/uri.md This HTML snippet illustrates how to use the `uri()` function within a Plates template to dynamically add a 'selected' class to the list item corresponding to the current page's URI. This is a common pattern for highlighting the active page in navigation menus. ```html ``` -------------------------------- ### PHP: Access Engine and Template Objects in Plates Extensions Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/extensions.md This PHP example illustrates how to access the Plates engine and template objects from within an extension. The engine is passed to the `register()` method, and the template is available as a public property, allowing extensions to interact with template data and other engine functionalities, such as accessing template data. ```PHP use League\Plates\Engine; use League\Plates\Extension\ExtensionInterface; class MyExtension implements ExtensionInterface { protected $engine; public $template; // must be public public function register(Engine $engine) { $this->engine = $engine; // Access template data: $data = $this->template->data(); // Register functions // ... } } ``` -------------------------------- ### PHP Plates: Applying Batch Functions for Advanced Escaping Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/escaping.md Illustrates how Plates' batch function calls allow applying multiple PHP functions to a variable during escaping. This example combines strip_tags and strtoupper to further process and sanitize input, offering flexible data manipulation before output. ```php

Welcome e($name, 'strip_tags|strtoupper')?>

``` -------------------------------- ### PHP Plates: Render Templates with Engine render() Method Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/overview.md This snippet demonstrates how to initialize the Plates engine and render templates using its `render()` method. It shows rendering a template in a subdirectory and a template with data. This is the primary way to use Plates templates. ```PHP // Create new Plates instance $templates = new League\Plates\Engine('/path/to/templates'); // Render a template in a subdirectory echo $templates->render('partials/header'); // Render a template echo $templates->render('profile', ['name' => 'Jonathan']); ``` -------------------------------- ### PHP: Fetch Template for Manual Output Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/nesting.md Illustrates the use of the `fetch()` function to retrieve the rendered template content as a string, allowing for manual output or further manipulation. Unlike `insert()`, `fetch()` does not automatically output the content. ```php fetch('partials/header')?> ``` -------------------------------- ### PHP Plates: Batch Functions with the e() Helper Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/functions.md Shows how the `e()` (escape) function also supports batch processing, allowing multiple transformations to be applied before escaping. This provides a concise way to prepare data for display while maintaining security. ```php

Welcome e($name, 'strip_tags|strtoupper')?>

``` -------------------------------- ### Generate Page Title in Go Template Source: https://github.com/thephpleague/plates/blob/v3/doc/layouts/partials/title.html This snippet defines a Go template logic to determine the appropriate title for a web page. It prioritizes a predefined 'Title' variable, then falls back to deriving it from the file system path, making it suitable for static site generators like Hugo. The output is a string representing the page's title. ```Go Template {{ $title := "" }} {{ if .Title }} {{ $title = .Title }} {{ else if and .IsSection .File }} {{ $title = path.Base .File.Dir | humanize | title }} {{ else if and .IsPage .File }} {{ $title = .File.BaseFileName | humanize | title }} {{ end }} {{ return $title }} ``` -------------------------------- ### PHP: Insert Template with Basic Path Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/nesting.md Demonstrates how to include another template using the `insert()` function with a direct file path. This function automatically outputs the rendered content directly into the current template. ```php insert('partials/header') ?>

Your content.

insert('partials/footer') ?> ``` -------------------------------- ### Plates URI Extension `uri()` Function API Reference Source: https://github.com/thephpleague/plates/blob/v3/doc/content/extensions/uri.md Detailed API documentation for the `uri()` function of the Plates URI extension, outlining its various parameter combinations, return types, and expected behaviors for URI manipulation and checking within templates. ```APIDOC function uri( [int $segment = null], [string $match = null], [string $successValue = null], [string $failureValue = null] ): mixed Description: The uri() function provides versatile URI checking and retrieval within Plates templates. Its behavior changes based on the parameters provided. Parameters: - $segment (int, optional): If provided, specifies a 1-indexed URI segment to retrieve or check against. - $match (string, optional): If $segment is an integer, this is the string to compare the segment against. If $segment is null, this is treated as a regular expression to match against the full URI. - $successValue (string, optional): The value to return if the URI check is successful. - $failureValue (string, optional): The value to return if the URI check fails. Return Values: - string: If no parameters are given, returns the full URI. - string: If $segment is an integer, returns the specified URI segment. - bool: If $match is provided and $successValue is not, returns true on success, false on failure. - string: If $successValue is provided, returns $successValue on success. - string: If $failureValue is provided, returns $failureValue on failure. ``` -------------------------------- ### PHP Plates: Stack Section Content with push() and unshift() Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/sections.md This snippet illustrates how to append or prepend content to existing sections instead of overwriting them. The `push()` method adds content to the end, while `unshift()` adds it to the beginning, which is useful for managing JavaScript libraries or CSS files required by child views. ```PHP push('scripts') ?> end() ?> unshift('styles') ?> end() ?> ``` -------------------------------- ### PHP: Add Folders to Plates Engine Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/folders.md This snippet demonstrates how to add new folders to a Plates engine instance using the `addFolder()` method. Folders allow grouping templates under different namespaces, each with its own file system path, making template organization easier. It requires an initialized `League\Plates\Engine` object. ```PHP // Create new Plates instance $templates = new League\Plates\Engine(); // Add folders $templates->addFolder('admin', '/path/to/admin/templates'); $templates->addFolder('emails', '/path/to/email/templates'); ``` -------------------------------- ### PHP: Load a Plates Extension into the Engine Object Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/extensions.md This PHP snippet demonstrates how to enable a custom extension by loading it into the Plates engine. The `loadExtension()` method is used with an instance of the extension class, making its registered functions available for use in templates. This is a crucial step for activating any custom extension. ```PHP $engine->loadExtension(new ChangeCase()); ``` -------------------------------- ### PHP: Render Templates from Plates Folders Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/folders.md This snippet shows how to render a template that resides within a previously defined folder. To access a folder's template, append the folder name with two colons before the template name. This method requires an existing Plates engine instance with configured folders and outputs the rendered template content. ```PHP $email = $templates->render('emails::welcome'); ``` -------------------------------- ### PHP: Preassign Data to Multiple Plates Templates Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/data.md Explains how to preassign the same data to an array of Plates templates using the `addData()` method. This is useful for sharing common data across several related templates, streamlining data management. ```php $templates->addData(['name' => 'Jonathan'], ['login', 'template']); ``` -------------------------------- ### PHP: Preassign Data to All Plates Templates Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/data.md Demonstrates how to assign data to all Plates templates by omitting the second parameter in the `addData()` method. This is suitable for global data that should be available across the entire application's templates, simplifying widespread data access. ```php $templates->addData(['name' => 'Jonathan']); ``` -------------------------------- ### PHP: Assign Data to Plates Templates Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/data.md Demonstrates various methods to assign data to Plates templates from application code. This includes using the engine's render method, the make method, and directly assigning data to a template object, enabling dynamic content rendering. ```php // Create new Plates instance $templates = new League\Plates\Engine('/path/to/templates'); // Assign via the engine's render method echo $templates->render('profile', ['name' => 'Jonathan']); // Assign via the engine's make method $template = $templates->make('profile', ['name' => 'Jonathan']); // Assign directly to a template object $template = $templates->make('profile'); $template->data(['name' => 'Jonathan']); ``` -------------------------------- ### PHP: Insert Template with Folder Namespace Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/nesting.md Shows how to use the `insert()` function with a folder namespace, allowing for organized template inclusion from registered directories. This provides a cleaner way to reference templates within specific sub-folders. ```php insert('partials::header') ?> ``` -------------------------------- ### PHP Plates: Check Template Existence with exists() Method Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/overview.md This snippet demonstrates how to verify if a template exists using the Plates engine's `exists()` method. It also shows how to perform the same check on an already instantiated template object. This is useful for dynamic template loading scenarios. ```PHP if ($templates->exists('articles::beginners_guide')) { // It exists! } if ($template->exists()) { // It exists! } ``` -------------------------------- ### PHP: Preassign Data to a Specific Plates Template Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/data.md Shows how to preassign data to a single, specific Plates template using the `addData()` method. This helps organize code by centralizing data assignment for templates that frequently require the same initial data. ```php $templates->addData(['name' => 'Jonathan'], 'emails::welcome'); ``` -------------------------------- ### Define Blog Article Template Extending Blog Layout in PHP Plates Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/layouts.md This snippet demonstrates a specific blog article template that extends the `blog` layout. It uses the `layout()` function to pass article-specific data and displays the article title and content within the defined sections. ```PHP layout('blog', ['title' => $article->title]) ?>

e($article->title)?>

e($article->content)?>
``` -------------------------------- ### PHP: Enable Folder Fallbacks in Plates Engine Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/folders.md This snippet demonstrates how to enable the folder fallback feature in Plates by passing `true` as the third parameter to `addFolder()`. When enabled, if a template is missing in a specific folder, Plates will automatically look for a template with the same name in the default folder. This feature is particularly helpful for managing themes and requires a default template path to be set for the engine. ```PHP // Create new Plates engine $templates = new \League\Plates\Engine('/path/to/default/theme'); // Add themes $templates->addFolder('theme1', '/path/to/theme/1', true); $templates->addFolder('theme2', '/path/to/theme/2', true); ``` -------------------------------- ### Define a Basic PHP Plates Layout Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/layouts.md This snippet demonstrates how to define a layout template using the `layout()` function in PHP Plates. It typically appears at the top of a template file and specifies the layout to be used for the current template's content. ```PHP layout('template') ?>

User Profile

Hello, e($name)?>

``` -------------------------------- ### PHP: Use Plates Folders with Template Functions Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/folders.md This snippet illustrates how to reference templates within folders when using Plates template functions, such as layouts or nested templates. The folder name is prepended with two colons before the template name, similar to rendering. This functionality relies on a Plates engine with defined folders and is used within a template file. ```PHP layout('shared::template') ?> ``` -------------------------------- ### Resolve Templates with Plates Theme Hierarchy (PHP) Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/themes.md Illustrates how templates are resolved when a theme hierarchy is active. It shows how `render()` calls implicitly fall back through the defined theme directories based on the hierarchy, prioritizing child themes. ```php $templates->render('home'); // templates/main/home.php $templates->render('layout'); // templates/user/layout.php $templates->render('header'); // templates/seasonal/header.php ``` -------------------------------- ### Implement Custom Template Path Resolution in Plates (PHP) Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/themes.md Shows how to replace the default template path resolution logic with a custom implementation. By assigning an instance of a class implementing `ResolveTemplatePath` to the Plates engine, developers can define their own advanced or specific path resolution strategies. ```php $plates = Engine::withResolveTemplatePath(new MyCustomResolveTemplatePath()); ``` -------------------------------- ### PHP: Applying Registered Functions with Plates Batch Calls Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/functions.md This PHP snippet demonstrates how to apply a registered custom function, like 'uppercase', using Plates' batch-compatible function calls. This method provides a concise way to process variables through functions, especially useful for chaining or applying multiple transformations. ```php

Hello e($name, 'uppercase')

``` -------------------------------- ### Define Main Layout Block in Go Template Source: https://github.com/thephpleague/plates/blob/v3/doc/layouts/_default/single.html This Go template snippet defines a block named 'main' which is commonly used as a primary layout. It includes placeholders for a page title and content, allowing child templates to extend or inject their specific data into these sections. This pattern facilitates consistent page structure across a web application. ```Go Template {{ define "main" }}\n\n{{ .Title }}\n============\n\n{{ .Content }} {{ end }} ``` -------------------------------- ### PHP Plates: Accessing Template Functions with $this Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/functions.md Demonstrates the basic syntax for calling a template function, specifically `escape()`, using the `$this` pseudo-variable within a Plates template. This ensures output is safely rendered by escaping potentially harmful characters. ```php

Hello, escape($name)?>

``` -------------------------------- ### PHP: Using Registered Functions Directly in Plates Templates Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/functions.md This PHP snippet illustrates how to invoke a previously registered custom function, such as 'uppercase', directly within a Plates template using the `$this->uppercase()` syntax. It also demonstrates the use of `$this->e()` for escaping output, ensuring secure rendering of dynamic content. ```php

Hello e($this->uppercase($name))

``` -------------------------------- ### PHP: Registering Custom Functions in Plates Engine Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/functions.md This PHP snippet demonstrates how to register a one-off custom function with the Plates templating engine. It shows creating a new Plates Engine instance and using `registerFunction` to add a callable that converts a string to uppercase. This allows for extending template functionality without creating full extensions. ```php // Create new Plates engine $templates = new \League\Plates\Engine('/path/to/templates'); // Register a one-off function $templates->registerFunction('uppercase', function ($string) { return strtoupper($string); }); ``` -------------------------------- ### PHP Plates: Use If Statement for Multi-line Default Section Content Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/sections.md This snippet shows how to display default content for a section when it's not present, especially for multi-line content. An `if` statement checks if the section exists using `section()`, rendering the default content if the section is empty or not defined. ```PHP ``` -------------------------------- ### PHP Plates: Access Rendered Section Content with section() Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/sections.md This snippet shows how to retrieve and display the content of a previously defined section. The `section()` function is used with the section's name to render its saved content within the current template or a layout template. ```PHP section('welcome')?> ``` -------------------------------- ### Configure Nginx for Plates Asset Filename Caching Source: https://github.com/thephpleague/plates/blob/v3/doc/content/extensions/asset.md For Nginx environments, this configuration snippet handles URL rewriting for filename-based cache busting. It defines a location block that uses try_files to serve the original asset file when a cache-busted URL (e.g., file.12345.css) is requested. ```nginx location ~* (.+)\.(?:\d+)\.(js|css|png|jpg|jpeg|gif)$ { try_files $uri $1.$2; } ``` -------------------------------- ### PHP Plates: Define Inline Default Section Content Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/sections.md This snippet demonstrates how to provide default content for a section if it's not implemented on a particular page. The default content is passed as the second parameter to the `section()` function, suitable for single-line or simple defaults. ```PHP ``` -------------------------------- ### Assign Data to PHP Plates Layout Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/layouts.md This snippet illustrates how to pass an array of data (variables) to a layout template using the `layout()` function. The assigned data becomes locally scoped variables within the layout, enabling dynamic content generation. ```PHP layout('template', ['title' => 'User Profile']) ?> ``` -------------------------------- ### Handle Select2 Change Event for URL Redirection Source: https://github.com/thephpleague/plates/blob/v3/doc/layouts/_default/baseof.html This JavaScript snippet initializes Select2 on a dropdown element and handles its change event. When a new option is selected, it modifies the current URL's second path segment based on the selected value and redirects the browser. It requires jQuery and the Select2 library to be loaded. ```JavaScript $('select.select2').select2().on('change', function(e) { var pathParts = window.location.pathname.split("/"); pathParts[1] = e.currentTarget.value; window.location.href = pathParts.join("/"); }); ``` -------------------------------- ### Define Main Site Layout in PHP Plates Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/layouts.md This snippet defines a basic HTML structure for a main site layout in PHP Plates. It includes a title and a content section, serving as the base template for other layouts to extend. ```PHP <?=$this->e($title)?> section('content')?> ``` -------------------------------- ### Manage Plates Engine Template File Extensions Source: https://github.com/thephpleague/plates/blob/v3/doc/content/engine/file-extensions.md This section provides various methods to manage template file extensions within the Plates PHP templating engine. You can set the default extension during engine creation, modify it post-instantiation, or disable automatic appending to manually specify extensions during rendering. ```PHP // Create new engine and set the default file extension to ".tpl" $template = new League\Plates\Engine('/path/to/templates', 'tpl'); ``` ```PHP // Sets the default file extension to ".tpl" after engine instantiation $template->setFileExtension('tpl'); ``` ```PHP // Disable automatic file extensions $template->setFileExtension(null); // Render template echo $templates->render('home.php'); ``` -------------------------------- ### PHP Plates: Basic Template Variable Escaping Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/escaping.md Demonstrates the fundamental use of escape() and its shorthand e() helper functions in Plates templates. These functions sanitize user-supplied input, ensuring it is safe for display as HTML and preventing cross-site scripting (XSS) vulnerabilities. ```php

Hello, escape($name)?>

Hello, e($name)?>

``` -------------------------------- ### PHP Plates: Define Base Template with Sections Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/inheritance.md This PHP code defines a base HTML template for a Plates application, illustrating template inheritance. It includes placeholders for a dynamic title, a main page content section, and a sidebar section. It also demonstrates setting default content for sections if not overridden by child templates, ensuring a fallback. ```PHP <?=$this->e($title)?>
section('page')?>
``` -------------------------------- ### Configure Apache for Plates Asset Filename Caching Source: https://github.com/thephpleague/plates/blob/v3/doc/content/extensions/asset.md To enable filename-based cache busting with the Plates Asset extension, URL rewriting is necessary. This Apache configuration snippet uses mod_rewrite to internally redirect requests for cache-busted filenames (e.g., file.12345.css) back to their original paths (e.g., file.css). ```apache RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L] ``` -------------------------------- ### PHP: Assign Data to Nested Template Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/nesting.md Explains how to pass an array of data (variables) to a nested template using the `insert()` or `fetch()` functions. The provided data becomes locally scoped variables within the included template, preventing conflicts with the parent template's scope. ```php insert('partials/header', ['name' => 'Jonathan']) ?>

Your content.

insert('partials/footer') ?> ``` -------------------------------- ### HTML: Access Data in Plates Templates Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/data.md Illustrates how to access locally scoped variables within a Plates template. It shows the use of the `$this->e()` method for escaping and outputting data, specifically the 'name' variable, ensuring safe display of content. ```html

Hello e($name)?>

``` -------------------------------- ### PHP Plates: Secure HTML Attribute Escaping Practices Source: https://github.com/thephpleague/plates/blob/v3/doc/content/templates/escaping.md Highlights the critical importance of correctly escaping variables within HTML attributes to prevent injection attacks. This snippet shows good and bad practices, emphasizing that attributes containing escaped variables must always be double-quoted for security. ```php <?=$this->e($name)?> <?=$this->e($name)?> <?=$this-e($name)?>> ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.