IruP has asked for the wisdom of the Perl Monks concerning the following question:

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?)

Replies are listed 'Best First'.
Re: Filtering content in Text::Xslate
by Anonymous Monk on Sep 06, 2017 at 08:31 UTC
Re: Filtering content in Text::Xslate
by hippo (Archbishop) on Sep 07, 2017 at 17:51 UTC