- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望这不是一个太晦涩的问题 - 我正在将 Algolia 搜索平台集成到我的一个项目中,以便能够无缝且轻松地进行搜索 yadda yadda。本质上,我正在寻找 Algolia 的 #hit-template
元素中业务目录的高级和低级布局的混合......逐字使用 {% if %} 不会相当工作......所以显然有一些我不理解/遗漏的东西。我需要纯粹在 javascript 中编辑某些内容吗?没有把握!什么是{%逐字%}?没有把握?!我可以在 type="text/template"的脚本中混合使用 javascript 和 html 吗?
{% verbatim %}
<script id="hit-template" type="text/template">
{% if _highlightResult.is_premium %}
<div class="card text-center mb-3">
<div class="crop-height bg-image-card card-header" style="background-image: url('{{ MEDIA_URL }}{{ get_image_url }}'); height: 160px !important;"></div>
<div class="card-header" style="color: #fff !important; background-color: {{ brand_colour }} !important; font-size: 1.3rem;">
{{{ _highlightResult.name.value }}}
</div>
<div class="card-body">
<p class="card-text" style="color: {{ business.brand_colour }} !important;"><a href="https://www.google.co.uk/maps/search/{{ google_maps_location }}" style="color: {{ brand_colour }};"><i class="fas fa-map-marker fa-2x" data-fa-transform="down-6"></i></a></p>
<p class="card-text"><small>{{ get_full_address }}</small></p>
<p class="card-text p-2">{{ description }}</p>
<a href="{{ absolute_url }}" class="btn btn-primary" style="background-color: {{ brand_colour }} !important; border-color: {{ brand_colour }} !important; color: #fff;">Visit Website</a>
</div>
<div class="card-footer text-muted">
<small>
<i class="fas fa-envelope" data-fa-transform="shrink-2"></i> {{ email }}
<i class="fas fa-phone" data-fa-transform="shrink-2"></i> {{ telephone }}</small></div>
<div style="display: none;">{{{ _highlightResult.sector.value }}}</div>
</div>
{% else %}
{% endif %}
</script>
{% endverbatim %}
最佳答案
{% verbatim %}
强制 Django 不解释模板文件中的 {
和 }
字符,因此 {% if %}
和 {% endif %}
在逐字标记内不起作用。您仍然可以在 verbatim 标记之外使用 Django 模板语法,并且仅在您希望 Django 忽略 {}
的地方使用 {% verbatim %}
(即在你的 Javascript 语法中)。
混合不同的模板语法时,可能很难解决使用 {
等特殊字符的歧义。解释器引擎无法解析您的意图。这里的一种解决方案是使用 Django 将您需要的变量存储到 Javascript 变量中,并使用 hogan.js
来处理它们。
<script>
window.MEDIA_URL = {{ MEDIA_URL }}
window.image_url = {{ get_image_url }}
</script>
{% if _highlightResult.is_premium %}
{% verbatim %}
<script id="hit-template" type="text/template">
// your Hogan.js stuff here, using `window` variables from Django stored as JS variables...
// Django will no longer interpret `{` and `}`, only Hogan.js will
</script>
{% endverbatim %}
{% endif %}
我对 Hogan.js 的了解还不够,无法指导您进一步了解具体细节。
关于javascript - Django 和 algolia - 使用 hogan + {% verbatim %} 标签的条件语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48752355/
我使用 expressjs 和 hoganjs 下面是我的 package.json 和 setup 。我有疑问是否必须检测 session 并仅在 Index.hjs 中的一部分提供不同的布局。 我
我想使用 hogan.js,但我目前用 jade 编写所有 html。我如何设置一个工作流程,让我可以在 jade 中编写模板,但仍然可以使用 hogan 进行编译? 感谢您的帮助! 最佳答案 我想你
我有一个带有 lambda 的 mustache 模板,如下所示: {{#myfunc}}myvalue{{/myfunc}} 它由 hogan.js 预编译如下: define(['hogan'],
我从文档中了解到 Hogan 不支持很多逻辑 - 但是您可以通过一些方法来操纵此模板系统来执行您需要的操作。 基本上,这就是我需要的(在伪代码中——假设 people.length >= 1): {{
我正在尝试学习expressjs,我有一个查询数据库的 Controller ,并返回一个 JSON 对象,如下所示: [ { _id: 58cb851721c1c107ab436686,
我使用的是 Hogan.js,它与 Mustache 规范兼容。而且我在实现多元化的可靠方法时遇到了麻烦。我想继续使用 Hogan 并使用 http://i18next.com/用于国际化处理 做这样
不完全确定“持久模板”是否是我所追求的,这是我第一次使用 Javascript 模板引擎。我很好奇是否有一种方法可以保持模板数据完整,以便在渲染文档后重新渲染文档...... 一个例子——我定义了一个
我正在寻找使用 hogan.js在浏览器中创建 html 表单模板。我读过 hogan 支持 i18n,但我找不到它如何工作的示例。你如何将翻译后的文本传递给 hogan,你在模板中放置了什么标签,我
我正在使用 Express JS 和 Hogan JS 模板引擎。我知道 hogan 是无逻辑模板,但我需要在 View 代码中执行 for 循环 以生成表字段。 我已经做了很多谷歌搜索,但没有找到任
你们中有人有使用 gulp + browserify + browserify-hogan 的经验吗? 我正在尝试将 Mustache 模板包含到我的浏览器化 JS Controller 中,显然它工
有人知道如何获取 hogan.js 3.0.0 dist 文件吗? 文件位于https://github.com/twitter/hogan.js是应使用 Node.js 编译以创建可分发文件的源文件
首先我想说我是 Node.js 新手。 我的问题是这样的。有没有一种方法可以将单一布局用于 HTML?分别类似于 MCV 和 ASP 中的共享 View 和主布局。 例如: //。 hello_wor
编译模板中是否可以有部分内容?看起来这是可能的,因为编译对象中引用了部分名称,但我不知道如何让它工作。 我正在服务器端 (node.js) 预编译 Hogan.js 模板,并使它们在客户端可用。这是模
我非常熟悉 javascript console.log() 和 php_dump() 函数,它们允许我们查看变量中的内容,我想知道 hogan.js 中是否有类似的函数可以让我们检查变量的内容。 最
是否可以在我的 django html 文件中包含以下内容? ${{ salePrice }}
是否有可能以任何方式使用 hogan.js 作为模板引擎,布局类似于“.NET 中的 Razor 或母版页”?我会得到这样的结果: 布局.hjs:包含“页眉”和“页脚” 和 索引.hjs:将包含 la
我计划在我的下一个项目中使用 Hogan.js。我想尝试一下。我只是被困住了,无法找到如何使用 Hogan.js 的助手。我之前用过 Handlebars。有没有办法在 Hogan 上做类似的事情?
我使用 Hogan.JS作为 JavaScript 模板库。它应该从外部文件加载 JavaScript 模板。人们可能可以在一个外部 JavaScript 文件中外包多个模板。 有人知道怎么做吗? 我
我目前正在使用 Algolia + Hogan 进行模板化。但我经常遇到以下错误,我在 CraftCMS 上运行 Algolia。 var hitTemplate = Hogan.compi
我在解决这个问题时遇到了问题。我正在尝试在新的 expressjs 应用程序中使用 hogan.js(通过 hogan-express),但我也想在前端使用 hogan.js(我将在其中使用 Back
我是一名优秀的程序员,十分优秀!