PHP 有哪些模板引擎选项?

发布于 2024-07-19 22:21:44 字数 52 浏览 4 评论 0原文

我想知道 PHP 中有哪些模板选项? 如果模板代码可以与 PHP 非常相似,那就最好了。

I wonder what options there are for templating in PHP? If the templating code can be very similar to PHP, it'd be best.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

杀手六號 2024-07-26 22:21:44

我可以推荐 Smarty

该模板是一个纯 HTML,带有一些用于 PHP 调用的额外标记。 该模板将自身编译为 PHP 并在服务器上运行。

I can recommend Smarty

The template is a plain HTML with some extra markup for PHP calls. The template compiles itself to a PHP and runs on the server.

同展鸳鸯锦 2024-07-26 22:21:44

php 有一个 “替代”语法,使其在 html 标签中更具吸引力,我强烈推荐它。

短标签虽然大多不被鼓励和/或嘲笑,但也有一个很好的优势:

<?php echo $variable; ?>

可以成为:

<?= $variable; ?>

你可以做这样的事情:

<ul>
    <? foreach ( $myListItems as $id => $itemText ) : ?>
    <li id="<?= $id; ?>">
        <?= $itemText; ?>
    </li>
    <? endforeach; ?>
</ul>

这是你将用 php 实现的最低级别的模板,但仍然非常可读,并且不需要您可以将控制器或模型逻辑与您的视图混合在一起。

there is an "alternative" syntax to php that makes it more attractive amidst html tags, I can highly recommend it.

Short tags, though mostly discouraged and/or ridiculed also have a nice advantage:

<?php echo $variable; ?>

can become:

<?= $variable; ?>

And you can do stuff like:

<ul>
    <? foreach ( $myListItems as $id => $itemText ) : ?>
    <li id="<?= $id; ?>">
        <?= $itemText; ?>
    </li>
    <? endforeach; ?>
</ul>

Which is the lowest level templating you are going to achieve with php, but is still very readable and it does not require you to mix in controller or model logic with your view.

瀟灑尐姊 2024-07-26 22:21:44

既然 PHP 一个模板引擎,那么总是...... PHP。

有些人觉得有必要添加更多内容。 Smarty 非常受欢迎。 就我个人而言,我从来没有看到过这一点,但对每个人来说都是如此。

Well since PHP is a templating engine there's always... PHP.

Some feel the need to add more. Smarty is very popular. Personally I've never seen the point but to each his own.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文