[英]Translating elements and adding enumeration IDs using Jinja2 templates?
I am creating pages that display slides from a slideshow (which are stored as images called slide001.png, slide002.png, etc.) along with transcripts of the voiceover. 我正在创建一些页面,这些页面显示来自幻灯片放映的幻灯片(存储为名为slide001.png,slide002.png等的图像)以及画外音的笔录。 The templates look like this: 模板如下所示:
<div class="transcript"> <div class =“ transcript”>
<p>Hello, and welcome to the first slide.</p> <p>您好,欢迎来到第一张幻灯片。</ p>
<p>This is the second slide.</p> <p>这是第二张幻灯片。</ p>
<p>/...and so on...</p> <p> / ...以此类推... </ p>
</div> </ div>
I want this translated into: 我希望将其翻译成:
<div class="transcript"> <div class =“ transcript”>
<div class="slide"> <div class =“ slide”>
<img src="slide001.png"/> <img src =“ slide001.png” />
<p>Hello, and welcome to the first slide.</p> <p>您好,欢迎来到第一张幻灯片。</ p>
</div> </ div>
...and so on for each slide... 对每张幻灯片等等
</div> </ div>
ie, each paragraph is wrapped in a div, and an img element is inserted with a consecutively-numbered image reference. 也就是说,每个段落都包裹在div中,并且img元素将插入带有连续编号的图像参考。 I'm doing this with JavaScript right now, but since I'm using Jinja2 to do other things (insert consistent headers and footers, creating forward/back links, etc.), I was hoping I could do the wrap-and-enumerate in Jinja2 as well. 我现在正在使用JavaScript进行此操作,但是由于我正在使用Jinja2做其他事情(插入一致的页眉和页脚,创建前向/后向链接等),所以我希望可以进行包装并枚举在Jinja2中也是如此。 Is it possible without heroic hackery? 没有英勇的黑客,有可能吗?
If you can get the data into the following format in your page then it can be rendered quite nicely. 如果您可以在页面中将数据转换为以下格式,则可以很好地呈现数据。
transcript = [{'image': 'filepath', 'text':'welcome...'},
{'image': 'filepath2', 'text':'slide2'},
{'image': 'filepath3', 'text':'slide3'}]
The Jinja can placed inline or moved to a macro but this will do the trick either way: Jinja可以内联放置或移动到宏,但这可以通过以下两种方法来实现:
<div class="transcript">
{% for slide in transcript %}
<div class="slide">
<img src="{{ slide.image }}"/>
<p>{{ slide.text }}</p>
</div>
{% endfor %}
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.