English 中文(简体)
动态(百分比使用)
原标题:Dynamic {% use %} statement in twig?
  • 时间:2011-11-22 10:12:18
  •  标签:
  • php
  • twig

我要谈以下几点:

我所有页都有一个基本模板,即“_page_base.twig。 它包括头盔和脚.。

然后,我有网页不同领域的模板:“topic.twig”、“section.twig”和“article.twig -其中每一部分均扩展了“_page_base.twig,迄今为止运作良好。

Now I want to write my articles. I would love to save them as .twig file as well, since I can edit the complete markup in my editor and just upload it.

Since I can t say that my article files just extend "article.twig" (multiple inheritance is not possible) I could tell the "article.twig" that it should use blocks from my different article-content twigfiles. The problem is: "use" statements have to be hardcoded!

我目前的解决办法是,将{%的“[PLACEHOLDER]”改为“article.twig,然后将模板装入一个插图,将持单人替换为正确的条款内容。 两次,然后将整件材料转至模板发动机。 什么东西。

你们是否为更好的解决办法提出任何想法?

问题回答

你们可以尝试包括主角。 由于这一标签接受动态名称模板以包括其中,你只是需要界定一个包含第tw条模板名称的变量。

{# on article.twig#}

{% set articles = [ someArticle.twig , ...] %}
{% for article in articles %}
    {% include article %}
{% endfor %}

{# on someArticle.twig #}
... Article text ...

如您需要定制<编码>中的某些内容。 您可以进入下一阶段:embe。 您应当界定<条码>某些条款.twig内的一个环形标签,这一组块将是持照的持有人。

{# on article.twig#}

{% set articles=[ someArticle.twig , ...] %}
{% for article in articles %}
    {% embed article %}
        {% block inside_text_article %}
            ... custom text ...
        {% endblock %}
    {% endembed %}
{% endfor %}


{# on someArticle.twig #}
    ... article text ...
    {% block inside_text_article %}default values{% endblock %}
    ... article text ...

除非我不理解这个问题,否则只显示一条条款就要求它也扩展第__页——基文。

如果你需要展示多种文章,你可以有一个模板,专门用于展示一份条款清单,该清单还将延伸至__页——基数。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签