[英]Tab all lines in a block
I have a JTwig (java flavor of twig) template like 我有一个JTwig(树枝的Java风格)模板,例如
SomeMagazine.twig: SomeMagazine.twig:
bla bla bla, and I quote:
{% block quote %}
{% endblock%}
and some more bla bla bla and so on
The child template invoking this one looks something like: 调用此模板的子模板如下所示:
MagQuote.twig: MagQuote.twig:
{% extends 'SomeMagazine.twig' %}
{% block quote %}
{% include 'QuotAuthTemplate.twig' with { auth : quote.author } %}
{% include 'QuotTextTemplate.twig' with { qtxt : quote.content } %}
{% endblock %}
quote
block with 1 tab at the begining quote
块的所有内容 MagQuote.twig
since it is composed by other templates so tabbing the template inclusion would only tab the first tab of the entire other template MagQuote.twig
它们进行MagQuote.twig
因为它是由其他模板组成的,因此对模板包含进行制表将仅对整个其他模板的第一个选项卡进行制表 Specifically for JTwig I tried creating my own function to tab contents ( SimpleJtwigFunction
, and add it to the EnvironmentConfiguration
at template instantiation) but I cannot figure out how to invoke it over the template contents since 特别是对于JTwig,我尝试创建自己的函数来制表内容(
SimpleJtwigFunction
,并在模板实例化时将其添加到EnvironmentConfiguration
),但由于无法自定义模板内容,因此我不知道如何调用它
{% set 'tmpltCnt' = {% include ...
nor this {% set 'tmpltCnt' = include ...
syntax works (and I cannot find it) {% set 'tmpltCnt' = {% include ...
或这个{% set 'tmpltCnt' = include ...
语法都不起作用(我找不到它) QuotAuthTemplate.twig
and QuotTextTemplate.twig
since they are used at some other places that require no tabs... QuotAuthTemplate.twig
和QuotTextTemplate.twig
内容,因为它们在其他不需要标记的地方使用了... {{ myTabbingMthd({% include ...
nor this {{ myTabbingMthd(include ...
syntax works (and I cannot find it) {{ myTabbingMthd({% include ...
或这个{{ myTabbingMthd(include ...
maybe just following the wrong approach here?... 也许只是在这里遵循错误的方法?
Answer (sort of...) 回答(有点...)
Best solutions o far has been to add some "tags" ; 最好的解决方案是添加一些“标签” 。 A unique-ish string that I can later use for pattern matching to later perform the line by line tabbing and replacing it on the resulting string removing the tags... Still hope someone comes up with something better since...
我以后可以将其用于模式匹配的独特字符串,以便稍后执行逐行制表并将其替换为除去标签的结果字符串...仍然希望有人提出更好的建议,因为...
Issues for this solution 此解决方案的问题
If you happen to be in the need (as I am) of having an indented block within another then the pattern matching will get confused, requiring you to either defined different tags for each, otherwise look this other answer for similar situations 如果您恰好需要(像我一样)在另一个模块中有一个缩进的块,那么模式匹配将变得混乱,要求您要么为每个定义不同的标签,否则在类似情况下寻找另一个答案
Is this the kind of thing you want where you can wrap the template using tabs (bootstrap): 这是您想要的那种东西,您可以在其中使用选项卡(引导程序)包装模板:
{% 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.