Filtering content in Text::Xslate
Asked Answered
E

0

10

In Mason i could define a filter:

<%filter Div($class)>
        <div class="<% $class %>">
                <% $yield->() %>
        </div>
</%filter>

And later i could use it

% $.Div("row") {{
   1 The "$yield->()" method returns everything from here (free text)
%       $.Div("col") {{
                2 even could have another nested filter, etc...
%       }}
% }}

with result

<div class="row">
    1 The "$yield->()" method returns everything from here (free text)
   <div class="col">
            2 even could have another nested filter, etc...   
   </div>
</div>

E.g. the $yield->() method returns everything what is inside of the enclosed filter.

Want achieve same functionality using Text::Xslate, but don't know how.

The closest thing what I found ,are the macro blocks where i could write:

: macro div -> ($cls,$str) {
<div class="<: $cls :>">
        <: $str :>
</div>
: }

and use it as

: div("row",
:       div("col",
:               "my string"
:       )
: )

but the my string must be quoted and : marked, so it is impossible to use any free html text. E.g. the following dies.

: div("row",

some free text here

:       div("col",
               nested
               here
:       )
: )

After the long introduction, the question is simple:

Exists in the Text::Xslate something as the Mason's $yield->() call, which returns the content of the enclosed filter call? (or if not exists, how i could mimic it?)

Electuary answered 1/4, 2017 at 8:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.