elazar/flysystem-twig-loader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

elazar/flysystem-twig-loader

最新稳定版本:1.0.0

Composer 安装命令:

composer require elazar/flysystem-twig-loader

包简介

Flysystem-backed loader for Twig templates

README 文档

README

PHP Version Support Packagist Version Software License Buy Me a Cofee

A custom loader for Twig v3 templates backed by a Flysystem v2/3 filesystem.

Released under the MIT License.

Supported Use Cases

This library is intended to be used in projects that meet the following criteria.

  1. Uses the Twig template engine.
  2. Uses the Flysystem filesystem access library.
  3. Needs to load Twig templates from a Flysystem filesystem.

Unsupported Use Cases

This library doesn't and won't support Flysystem v1 or Twig v1 or v2. If you want a library similar to this one that is compatible with those versions, see cedricziel/twig-loader-flysystem.

Requirements

  • PHP 8.2+
  • Flysystem 2.1+
  • Twig 3

Installation

Use Composer.

composer require elazar/flysystem-twig-loader

Note: This will automatically install the latest version of the Flysystem core library that is available for your environment. However, you must handle installing adapters yourself. See the Flysystem documentation for a list of official adapters.

Usage

The example below uses the league/flysystem-local adapter that is automatically installed with the Flysystem core library.

<?php

/**
 * 1. Instantiate the Flysystem filesystem reader with an appropriate adapter.
 *
 * Note: Because the Twig loader only executes read operations, it technically only
 * requires an instance of a class that implements the Flysystem FilesystemReader
 * interface (e.g. League\Flysystem\Filesystem).
 *
 * @see https://flysystem.thephpleague.com/docs/getting-started/
 */

$filesystemAdapter = new League\Flysystem\Local\LocalFilesystemAdapter('/path/to/templates');

$filesystemReader = new League\Flysystem\Filesystem($filesystemAdapter);

/**
 * 2. Instantiate the Twig template loader and pass the Flysystem filesystem
 *    reader to it.
 *
 * @see https://twig.symfony.com/doc/3.x/api.html#loaders
 */

$templateLoader = new Elazar\FlysystemTwigLoader\FlysystemLoader($filesystemReader);

/**
 * 3. Instantiate the Twig environment and pass the Twig template loader to it.
 *
 * @see https://twig.symfony.com/doc/3.x/api.html#basics
 */

$twig = new Twig\Environment($templateLoader);

/**
 * 4. Load or render templates as normal with Twig; they will be sourced from
 *    the Flysystem filesystem object.
 *
 * @see https://twig.symfony.com/doc/3.x/api.html#loading-templates
 * @see https://twig.symfony.com/doc/3.x/api.html#rendering-templates
 */

$path = '/path/to/template.html.twig';
$data = ['the' => 'variables', 'go' => 'here'];

$template = $twig->load($path);
echo $template->render($data);

// or

echo $twig->render($path, $data);

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-08