youcanshop/liquid

主题的Liquid模板引擎。

v1.1.2 2023-11-23 09:40 UTC

This package is auto-updated.

Last update: 2024-09-27 15:33:04 UTC


README

A PHP version of Ruby's Liquid Template Engine for YouCan Shop theme development.
Liquid允许您为电子商务店铺创建灵活和动态的主题。

为什么要使用Liquid?

  • 独立的编译和渲染阶段以提高性能。
  • 简单的语法创建动态模板。
  • 创建可重用的组件

安装

通过Composer安装

composer require liquid/liquid

示例用法

require 'vendor/autoload.php';
use Liquid\Template;

$template = new Template();
$template->parse('Hello, {{ name }}!');
echo $template->render(['name' => 'world']);

创建YouCan主题

Liquid在模板文件中使用对象标签过滤器的组合来显示动态内容。

它看起来像什么?

  {% if user %}
    <p>Welcome back, {{ user.name }}!</p> <!-- Outputs a welcome message if the user is logged in -->
  {% else %}
    <p>Welcome to our store!</p> <!-- Outputs a generic welcome message if the user is not logged in -->
  {% endif %}
</header>

<main>
  <h1>{{ product.title }}</h1> <!-- Outputs the product title -->
  <p>{{ product.description }}</p> <!-- Outputs the product description -->
  <p>Price: {{ product.price | money }}</p> <!-- Outputs the product price formatted as money -->
</main>
  1. 输出标签 ({{ }}):用于显示内容。
  2. 逻辑标签 ({% %}):用于执行条件判断和循环等操作。
  3. 过滤器 (|):用于格式化变量的输出。
  4. 变量:用于存储可以在模板中渲染的数据。

更多详细信息,请访问YouCan主题文档