简体   繁体   中英

Extract content of a block from a twig template

Is there any way to extract the source content of a twig template in an acceptable way? Of course I can use a regex pattern, but I think this is not the best solution.

If I have this:

{% block test %}
This is a test!
{% endblock %}

I want to extract this by using the name of the block:

This is a test!

Suppose file we have file: file.html.twig with

{% block test %}
This is a test!
{% endblock %}

to extract This is a test! execute a command:

sed '/{%/ d' file.html.twig

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM