0

I have a JTwig (java flavor of twig) template like

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:

{% extends  'SomeMagazine.twig' %}
{% block quote %}
{% include 'QuotAuthTemplate.twig' with { auth : quote.author } %} 
{% include 'QuotTextTemplate.twig' with { qtxt : quote.content } %} 
{% endblock %}
  1. I would like to get all contents of the quote block with 1 tab at the begining
  2. Notice I cannot tab them in 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
  3. 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

    • I cannot (don't know how to) save them in a variable so that I can invoke my method over it; neither this {% set 'tmpltCnt' = {% include ... nor this {% set 'tmpltCnt' = include ... syntax works (and I cannot find it)
    • I cannot tab the contents at the QuotAuthTemplate.twig and QuotTextTemplate.twig since they are used at some other places that require no tabs...
    • I cannot (don't know how to) call the function over the include itself; neither this {{ myTabbingMthd({% include ... nor this {{ myTabbingMthd(include ... syntax works (and I cannot find it)

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

Ordiel
  • 2,151
  • 3
  • 31
  • 47

1 Answers1

0

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 %}
karen
  • 693
  • 1
  • 10
  • 29
  • No, what I am asking is literally using the template I posted, how can I automatically tab the contents of a block. Besides, now you are introducing HTML, to create a simulated format for my scenario, but that is unnecessary in my case, just need to know how to tab the entire contents of the block – Ordiel Feb 20 '19 at 21:22