我有一个简单的搜索表单,我想用Jade实现.
form
input(
type="text"
size="16"
placeholder="Enter your keywords")
input(
type="button"
value="Search")
Run Code Online (Sandbox Code Playgroud)
输出呈现为:
<form>
<input type="text" size="16" placeholder="Enter your keywords">
<input type="button" value="Search">
</form>
Run Code Online (Sandbox Code Playgroud)
这是完美的,除了换行符导致我的按钮和搜索按钮之间的空格.我在文本框和按钮之间不需要空格.我需要代码呈现如下:
<form>
<input type="text" size="16" placeholder="Enter your keywords"><input type="button" value="Search">
</form>
Run Code Online (Sandbox Code Playgroud)
但是,我正在使用此项目来创建需要在其HTML表单中读取的代码,并且不能简单地从我的项目中删除整个空格.
有没有办法按照指示输出我的表格,同时在我的文档的其余部分保留白色间距和换行符?
根据FreeMarker include语句文档,您可以像这样制作页眉和页脚感知模板:
<#include "/header.ftl">
<!-- Content of my this page -->
<#include "/footer.ftl">
Run Code Online (Sandbox Code Playgroud)
但如果我的网络应用程序有数百个页面/视图,这是一个冗余的复制意大利面.如果在FreeMarker中有一个" 布局 "概念,那就太棒了,我可以说" 嘿,这是一个布局: "
<#include "/header.ftl">
<@import_FTL_Somehow>
<#include "/footer.ftl">
Run Code Online (Sandbox Code Playgroud)
然后为每个视图创建/页(单独的模板index.ftl,contactUs.ftl等等),然后告诉FreeMarkers其中FTL文件"使用"的布局.这样我就不必在每个模板文件中继续指定页眉/页脚包含.
FreeMarker是否支持这种概念?
使用kubectl apply -k,您可以覆盖资源配置(您已经定义)。你也可以创建资源吗?
在我的具体情况下,我想为开发环境创建一个本地卷。不过,我的基本文件夹中没有此资源。
\n\n我的文件夹结构是这样的:
\n\n\n\nRun Code Online (Sandbox Code Playgroud)\n~/someApp\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 base\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 deployment.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 service.yaml\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 overlays\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 development\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cpu_count.yaml\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 replica_count.yaml\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 volume.yaml <--- *Is this possible*?\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 production\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cpu_count.yaml\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 replica_count.yaml\n
准备模板时出现错误。谁能告诉你如何解决?
\n如有必要,还可以编辑变量。
\n vars:\n All\xd0\xa1ountry:\n - "name1"\n - "name2"\n name1:\n - "region1a" \n - "region1b" \n name2:\n - "region2a"\n - "region2b"\nRun Code Online (Sandbox Code Playgroud)\n代码
\n{% for country in All\xd0\xa1ountry %} \n{name: "{{ country }}",{% for count in {{ country }} %}My country = {{ count }}\n{% endfor %}{% endfor %}\nRun Code Online (Sandbox Code Playgroud)\n结果是一个错误\nAnsibleError:模板化字符串时出现模板错误:预期标记“:”,得到“}”
\n是的,最后我希望得到整个列表的输出
\nname: "name1 My country = "region1a" My country = "region1b" \nname: "name2: My country = "region2a" My country = "region2b"\nRun Code Online (Sandbox Code Playgroud)\n 我正在评估 Kustomize 作为我的项目的模板解决方案。我想要一个选项来替换特定的键值对。
ports:
- containerPort: 8081
resources:
limits:
cpu: $CPU_LIMIT
memory: $MEMORY_LIMIT
requests:
cpu: $CPU_REQUESTS
memory: $MEMORY_REQUESTS
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,我想用配置驱动的值替换 CPU_LIMIT。我可以通过哪些选项来使用 Kustomize 执行此操作?
在Razor View Engine模板中,我想执行以下操作:我想在html 属性的双引号之间放置一些代码.麻烦的是我要插入的代码片段本身包含一些双引号.
<a href="Url.Action("Item", new { id = Model.Item.Id, page = page });">@page</a>
Run Code Online (Sandbox Code Playgroud)
你可以很容易地看到事情变得非常糟糕:-)我知道我可以计算变量中的链接然后使用它,但我宁愿不:
@{ var action = Url.Action("Question", new { id = Model.Question.Id, page = page }); }
<a href="@action">@page</a>
Run Code Online (Sandbox Code Playgroud) Node/Express是否有像RABL(https://github.com/nesquena/rabl)或JBuilder 这样的JSON模板引擎?(http://railscasts.com/episodes/320-jbuilder?view=asciicast).我不是指像Handlebars,Jade或Underscore.js这样的HTML模板引擎.我的意思是JSON模板引擎.这些库简化了选择和选择JSON的元素和关联的过程.
我似乎找不到有关Pug/Jade的条件的详细文档,考虑在if语句中使用&&.
我试图实现这个目标:
if(true && string == 'saved'){
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用嵌套的if,但它似乎也不起作用:
if entryopen
if !submitted
button
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!
import jinja2
from jinja2 import Template
records = [{'a':1,'b':1, 'c':1},{'a':1,'b':1, 'c':1}, {'a':2,'b':1, 'c':1}, {'a':3,'b':1, 'c':1}]
t = jinja2.Template("""
{% set record_info = dict() %}
{% for item in records %}
{% set key = str(item['a'])+str(item['b'])+str(item['c']) %}
{% if key in record_info %}
{% set record_info.key += 1 %}
{% else %}
{% set record_info.key = 1 %}
{% endif %}
{% endfor %}
{{record_info}}""")
Run Code Online (Sandbox Code Playgroud)
这给了我:
Traceback (most recent call last):
File "<stdin>", line 11, in <module>
File "/Library/Python/2.7/site-packages/jinja2/environment.py", line 945, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 jinja 模板中创建 bash 脚本。我有以下几行:
SOME_ARRAY_COUNT=${#SOME_ARRAY[@]}
Run Code Online (Sandbox Code Playgroud)
但它会抛出一个错误:
AnsibleError: template error while templating string: Missing end of comment tag
Run Code Online (Sandbox Code Playgroud)
经过调查,我发现{% raw %}...{% endraw %}可以使用块来获取文字,但它仍然无法{#获得类似的错误:
An unhandled exception occurred while templating
Error was a <class 'ansible.errors.AnsibleError'>, original message: template error while templating string: Missing end of comment tag
Run Code Online (Sandbox Code Playgroud)
有没有解决这个问题而不改变 bash 逻辑的方法?
谢谢
更新:包括示例
Ansible 剧本:
... more ansible playbook stuff ...
tasks:
- name: create script
template:
src: "src/path/to/script.sh.j2"
dest: "dest/path/to/output/script.sh"
- name: user data script as string …Run Code Online (Sandbox Code Playgroud) templating ×10
ansible ×2
html ×2
jinja2 ×2
kustomize ×2
pug ×2
asp.net-mvc ×1
conditional ×1
express ×1
freemarker ×1
json ×1
kubernetes ×1
layout ×1
line-breaks ×1
node.js ×1
python ×1
python-2.7 ×1
razor ×1
whitespace ×1