任何人都知道如何连接树枝中的字符串?我想做的事情如下:
{{ concat('http://', app.request.host) }}
Run Code Online (Sandbox Code Playgroud) 我想将"模板"文件的输出传递给MySQL,该文件包含${dbName}
散布的变量.什么是命令行实用程序来替换这些实例并将输出转储到标准输出?
我目前在express.js应用程序中处理handlebars.js.为了保持模块化,我将所有模板分成了部分.
我的问题:我找不到通过部分调用传递变量的方法.假设我有一个部分看起来像这样:
<div id=myPartial>
<h1>Headline<h1>
<p>Lorem ipsum</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我们假设我使用名称"myPartial"注册了这个部分.在另一个模板中,我可以说:
<section>
{{> myPartial}}
</section>
Run Code Online (Sandbox Code Playgroud)
这工作正常,部分将按预期呈现,我是一个快乐的开发人员.但我现在需要的是一种通过此调用传递不同变量的方法,例如,如果给出标题,则在部分内部进行检查.就像是:
<div id=myPartial>
{{#if headline}}
<h1>{{headline}}</h1>
{{/if}}
<p>Lorem Ipsum</p>
</div>
Run Code Online (Sandbox Code Playgroud)
并且invokation应该看起来像这样:
<section>
{{> myPartial|'headline':'Headline'}}
</section>
Run Code Online (Sandbox Code Playgroud)
或者.
我知道,在渲染模板之前,我能够定义所需的所有数据.但我需要一种方法来解决这个问题.有可能吗?
我正在编写一个脚本来自动为我自己的web服务器创建Apache和PHP的配置文件.我不想使用像CPanel或ISPConfig这样的任何GUI.
我有一些Apache和PHP配置文件的模板.Bash脚本需要读取模板,进行变量替换并将解析后的模板输出到某个文件夹中.最好的方法是什么?我可以想到几种方法.哪一个是最好的还是有更好的方法可以做到这一点?我想在纯Bash中做到这一点(例如在PHP中很容易)
template.txt:
the number is ${i}
the word is ${word}
Run Code Online (Sandbox Code Playgroud)
script.sh:
#!/bin/sh
#set variables
i=1
word="dog"
#read in template one line at the time, and replace variables
#(more natural (and efficient) way, thanks to Jonathan Leffler)
while read line
do
eval echo "$line"
done < "./template.txt"
Run Code Online (Sandbox Code Playgroud)
顺便说一句,如何在此处将输出重定向到外部文件?如果变量包含引号,我是否需要逃避某些事情?
2)使用cat&sed替换每个变量的值:
给出template.txt:
The number is ${i}
The word is ${word}
Run Code Online (Sandbox Code Playgroud)
命令:
cat template.txt | sed -e "s/\${i}/1/" | sed -e "s/\${word}/dog/"
Run Code Online (Sandbox Code Playgroud)
对我来说似乎不好,因为需要逃避许多不同的符号,并且对于许多变量,这条线太长了.
你能想到其他一些优雅而安全的解决方案吗?
如果我看Razor视图引擎,然后我看到一个非常漂亮和简洁的语法并不特别依赖于生成HTML.所以我想,这将是多么容易使用在发动机外部asp.net中的一个"正常"的.NET环境,例如生成文本,代码,...
欢迎使用任何指针,示例,注释或解释.
我正在利用handlebars.js作为我的模板引擎,并且我希望只有当它是模板配置对象中包含的数组中的最后一项时才显示条件段.
{
columns: [{<obj>},{<obj>},{<obj>},{<obj>},{<obj>}]
}
Run Code Online (Sandbox Code Playgroud)
我已经拉了一个助手来做一些相等/更大/更少的比较,并且已经成功识别出这样的初始项目但是没有运气来访问我的目标数组的长度.
Handlebars.registerHelper('compare', function(lvalue, rvalue, options) {...})
"{{#each_with_index columns}}"+
"<div class='{{#equal index 0}} first{{/equal}}{{#equal index ../columns.length()}} last{{/equal}}'>"+
"</div>"+
"{{/each_with_index}}"
Run Code Online (Sandbox Code Playgroud)
有没有人知道一个快捷方式,不同的方法,以及一些把手的优点,这将使我不必撕裂到handlebars.js引擎,以确定最佳的课程?
我有一个PHP函数,我用它来输出标准的HTML块.它目前看起来像这样:
<?php function TestBlockHTML ($replStr) { ?>
<html>
<body><h1> <?php echo ($replStr) ?> </h1>
</html>
<?php } ?>
Run Code Online (Sandbox Code Playgroud)
我想在函数内部返回(而不是回显)HTML.有没有办法在不在字符串中构建HTML(上面)的情况下执行此操作?
我已经完成了关于Facelets模板的教程.
现在我尝试创建一个与模板不在同一目录中的页面.我有页面样式的问题,因为样式用相对路径引用,如下所示:
<link rel="stylesheet" href="style_resource_path.css" />
Run Code Online (Sandbox Code Playgroud)
我可以通过以下开头使用绝对引用/
:
<link rel="stylesheet" href="/project_root_path/style_resource_path.css" />
Run Code Online (Sandbox Code Playgroud)
但是,当我将应用程序移动到不同的环境时,这将给我带来麻烦.
所以我想知道在Facelets中引用CSS(以及JS和图像)资源的最佳方法是什么?
我正在评估Slim作为个人项目中HAML的替代品,它似乎不像HAML那样优雅地处理HTML5数据属性.我希望有人也可能碰到这个,或者可能已经知道我在他们的文档中还没有找到的选项/语法.
HAML允许您通过使用嵌套哈希来定义HTML 5数据属性,如下所示:
%a{data: {key1: 'val', key2: 'val'}}
导致
<a data-key1='val' data-key2='val'></a>
在我的HTML中,我可以定义这些淘汰的foreach绑定:
<!-- ko foreach: customer -->
<div data-bind="text: id" />
<!-- /ko -->
Run Code Online (Sandbox Code Playgroud)
VS
<div data-bind="foreach: customer">
<div data-bind="text: id" />
</div>
Run Code Online (Sandbox Code Playgroud)
这两种方法之间的差异在哪里?
templating ×10
javascript ×3
bash ×2
arrays ×1
asp.net ×1
asp.net-mvc ×1
command-line ×1
facelets ×1
haml ×1
helpers ×1
html ×1
jsf ×1
jsf-2 ×1
knockout.js ×1
php ×1
razor ×1
resources ×1
ruby ×1
slim-lang ×1
string ×1
syntax ×1
templates ×1
twig ×1