简体   繁体   English

想要将渲染 html 转换为带有变量和所有东西的 nunjucks

[英]want to convert render html to nunjucks with variable and every thing

becuase i want to manuplate/add some html tags after html render and save into nunjucks (like before rendering);因为我想在 html 渲染后手动/添加一些 html 标签并保存到 nunjucks 中(就像渲染之前一样);

nunjucks before render渲染前的 nunjucks

<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渲染和 html 修改后的 nunjucks

<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请解决并提出任何方法来做这件事 pleassssss

If you want the output to look like the original nunjucks logic you typed in, then you can try the following technique.如果您希望 output 看起来像您输入的原始 nunjucks 逻辑,那么您可以尝试以下技术。 On your HTML template within your nunjucks project...在你的 nunjucks 项目中的 HTML 模板上......

<pre>
  <code>
    <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>
  </code>
</pre>


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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