Pesto PHP 模板引擎

dev-main 2022-02-10 13:04 UTC

This package is auto-updated.

Last update: 2024-09-10 18:51:55 UTC


README

  • 缓存 必须可由 www-data 写入
  • 组件
  • 视图

命令

#Components = [<ComponentName>,...]
定义当前模板中可用的组件

#Extends = [<TemplateName>]
定义一个模板,其他模板将扩展到该模板。只能有一个条目

@Variable
在自定义组件中声明变量并在组件本身中渲染该变量

#Block(<blockname>) <content> #Endblock
定义内容应该渲染在哪个父块中

#Block(<blockname>)#Endblock
定义子块内容应该放置的位置

在块内部声明的 PHP 变量只能在块内部访问。在块外部声明的 PHP 变量可以在任何地方访问。

{{ <PHPVariable> }}
输出 PHP 变量。支持对象和数组。变量会自动转义。

示例

渲染模板的示例

$p = new Pesto(__DIR__ . "/");
$p->enableCaching = false; #True or false

$r = $p->render('Page'); #Templatename without ending
echo $r;

模板的示例

Base.pesto.php

#Components = [Alert]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>#Block(title)#Endblock</title>
</head>
<body>
<Alert @title="HWinPesto" @attribute="Hello World in Page"></Alert>
#Block(content)#Endblock
</body>
</html>

扩展模板的示例

Page.pesto.php

#Components = [Alert]
#Extends = [Base]

#Block(title)
This is a title
#Endblock

#Block(content)
<div>
	<p>Dies ist ein Text</p>
	<div>
		<Alert @title="Beispiel" @attribute="Hello World">Moin</Alert>
		<Alert @title="Beispiel2" @attribute="Hello World2"></Alert>
	</div>
	<?php
	$news = "thisisnews";
	$image = new Image("Image Name","Image URL");
	?>
    <p>{{ $news }}</p>
    <p>{{ $image->name }}</p>
</div>
#Endblock

组件的示例

Alert.pesto.php

确保将字符串用引号括起来

<div class="alert">
    <h1>{{ @title }}</h1>
    <p>{{ @attribute }}</p>
    <p>{{ @content }}</p>
    <p>{{ function( "@string", @variableOrInt }}</p>
<div>