migrify/latte-to-twig

此包已被弃用且不再维护。作者建议使用symplify/latte-to-twig-converter包代替。

Latte to Twig 转换器将 Latte 转换为 Twig

9.4.24 2021-08-02 17:05 UTC

This package is auto-updated.

Last update: 2021-08-02 17:09:04 UTC


README

Downloads total

你想将你的Latte模板转换为Twig吗?

之前

{foreach $values as $key => $value}
    {$value->getName()}

    {if isset($value['position'])}
        {$value['position']|noescape}
    {else}
        {var $noPosition = true}
    {/if}
{/foreach}

之后

{% for key, value in values %}
    {{ value.getName() }}

    {% if value.position is defined %}
        {{ value.position|raw }}
    {% else %}
        {% set noPosition = true %}
    {% endif %}
{% endfor %}

还有更多!

此包不会为你完成所有工作,但它将帮助你完成80%的繁琐工作。

安装

composer require symplify/latte-to-twig-converter --dev

用法

它会扫描所有 *.twig/*.latte 文件,并将其转换为 *.twig

vendor/bin/latte-to-twig convert file.twig
vendor/bin/latte-to-twig convert /directory

手动处理这些情况

一些代码没有清晰的路径 - Twig中有更多选择,所以最好手动迁移。

continueIf

-{continueIf $cond}
+{% if cond %}
-{$value}
+    {{ value }}
+{% endif %}

breakIf

-{breakIf $cond}
+{% if cond === false %}
-{$value}
+    {{ value }}
+{% endif %}

就这样 :)


报告问题

如果你遇到错误或想要请求新功能,请访问Symplify monorepo问题跟踪器

贡献

此包的源代码包含在Symplify monorepo中。我们欢迎在symplify/symplify上对此包做出贡献。