如何处理嵌套模板变量? [英] How to handle nested template variables?

查看:286
本文介绍了如何处理嵌套模板变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前拥有一个嵌入式< iframe> ,它有一个硬连线的静态网址:

I currently have an embedded <iframe> that has a hard wired static url:

<iframe src="{% static 'docs/ver600/technical-reference-guide/_build/html/index.html' %}" frameborder="0" class="full-screen"></iframe>

我想用静态字符串中的变量替换部分。

I would like replace parts of the static string with variables.

例如,技术参考指南只是一个文档名称变量。显然,嵌入模板变量不起作用:

For example, the "technical-reference-guide" is just a document name variable. Obviously, just embedding a template variable doesn't work:

<iframe src="{% static 'docs/ver600/{{ doc_name }}/_build/html/index.html' %}" frameborder="0" class="full-screen"></iframe>

在模板中处理此类动态互动的最佳方式是什么?

What would the best way for handling this type of dynamic interaction within a template?

此外,文档名称是从页面块中派生的:

Also, the document name is derived from the page slug:

{% page_attribute 'slug' %}

如果这改变了所有的回复。

if that alters responses at all.

推荐答案

尝试添加 filter( docs here )。它可以将模板标签中的字符串和变量值(假设它们也是字符串)链接在一起。

Try the add filter (docs here). It can chain together strings and variable values (assuming they're also strings) inside a template tag.

示例:

{% static 'docs/ver600/'|add:doc_name|add:'/_build/html/index.html' %}

这篇关于如何处理嵌套模板变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆