簡體   English   中英

制表符中的所有行

[英]Tab all lines in a block

我有一個JTwig(樹枝的Java風格)模板,例如

SomeMagazine.twig:

bla bla bla, and I quote:
{% block quote %}
{% endblock%}

and some more bla bla bla and so on

調用此模板的子模板如下所示:

MagQuote.twig:

{% extends  'SomeMagazine.twig' %}
{% block quote %}
{% include 'QuotAuthTemplate.twig' with { auth : quote.author } %} 
{% include 'QuotTextTemplate.twig' with { qtxt : quote.content } %} 
{% endblock %}
  1. 我想在開始時使用1個選項卡獲取quote塊的所有內容
  2. 請注意,我無法在MagQuote.twig它們進行MagQuote.twig因為它是由其他模板組成的,因此對模板包含進行制表將僅對整個其他模板的第一個選項卡進行制表
  3. 特別是對於JTwig,我嘗試創建自己的函數來制表內容( SimpleJtwigFunction ,並在模板實例化時將其添加到EnvironmentConfiguration ),但由於無法自定義模板內容,因此我不知道如何調用它

    • 我不能(不知道如何)將它們保存在變量中,以便可以在其上調用我的方法。 這個{% set 'tmpltCnt' = {% include ...或這個{% set 'tmpltCnt' = include ...語法都不起作用(我找不到它)
    • 我無法在QuotAuthTemplate.twigQuotTextTemplate.twig內容,因為它們在其他不需要標記的地方使用了...
    • 我不能(不知道如何)通過包含本身調用函數; 這個{{ myTabbingMthd({% include ...或這個{{ myTabbingMthd(include ...

也許只是在這里遵循錯誤的方法?

回答(有點...)

最好的解決方案是添加一些“標簽” 我以后可以將其用於模式匹配的獨特字符串,以便稍后執行逐行制表並將其替換為除去標簽的結果字符串...仍然希望有人提出更好的建議,因為...

此解決方案的問題

如果您恰好需要(像我一樣)在另一個模塊中有一個縮進的塊,那么模式匹配將變得混亂,要求您要么為每個定義不同的標簽,否則在類似情況下尋找另一個答案

這是您想要的那種東西,您可以在其中使用選項卡(引導程序)包裝模板:

{% block quote %}
    <div class="panel-heading ">
        <ul class="nav nav-tabs">
            <li class="active">
                <a data-toggle="tab" class="" role="tab" href="#tab1">Tab 1</a>
            </li>

            <li>
                <a data-toggle="tab" class="" role="tab" href="#tab2">Tab 2</a></li>
            </li>
        </ul>
    </div>
    <div class="panel-body">
        <div class="tab-content">
            <div id="tab1" class="tab-pane fade in active">
                {% include 'QuotAuthTemplate.twig' with { auth : quote.author } %} 
            </div>
            <div id="tab2" class="tab-pane fade">
                {% include 'QuotTextTemplate.twig' with { qtxt : quote.content } %} 
            </div>
        </div>
    </div>
{% endblock %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM