mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 634 forks source link

want to convert render html to nunjucks with variable and every thing. #1427

Open shoaib3456 opened 1 year ago

shoaib3456 commented 1 year ago

becuase i want to manuplate/add some html tags after html render and save into nunjucks (like before rendering);

nunjucks before render

<div class="ps-4">
        <h1>{{heading}}</h1>
        {% if isShowLi %}
            <div class="px-4">
                {% for item in items %}
                    <div>{{item.name}}</div>
                {% endfor %}
            </div>
        {% endif %}
</div>

nunjucks after render and html modification

<div class="ps-4">
        <h1>hello world</h1>
          <img src="abc.png" />
            <div class="px-4">
                    <div>item 1</div>
                    <div>item 2</div>
                    <div>item 3</div>
                    <div>item 4</div>
                    <div>item 5</div>
            </div>
 </div>

and i want it like that

<div class="ps-4">
        <h1>{{heading}}</h1>
       <img src="abc.png" />
        {% if isShowLi %}
            <div class="px-4">
                {% for item in items %}
                    <div>{{item.name}}</div>
                {% endfor %}
            </div>
        {% endif %}
 </div>

please solve and suggest any way to do this thing pleassssss