Swig模板和AngularJS都使用双花括号表示法.如何在Swig for Angular中逃脱双重曲线?
鉴于:
我希望我能够让Swig突出显示固定,但我只是中途.
以下是我得到的结果突出显示.Swig代码按预期突出显示,但HTML不再突出显示.
我也尝试过安装和启用HTML textmate包,但是当激活HTML和Swig包时,代码只会突出显示为HTML.如果我禁用HTML捆绑包但Swig捆绑包仍然处于活动状态,我只会突然显示Swig.
我的问题:如何在Windows上的WebStorm中的同一文件中突出显示Swig代码和HTML代码?
结果:

这是我在WebStorm 9中的Textmate Bundles配置:

同样,只需选择HTML包即可启用它.
ide syntax-highlighting intellij-idea webstorm swig-template
我正在尝试使用节点(表达v3.1.0)设置Consolidate,以使用Swig.我一直在收到错误
错误:无法在Module.require的Function.Module._load(module.js:280:25)的Function.Module._resolveFilename(module.js:338:15)中找到模块'swig'(module.js:362:17) )at function(export.js:378:17)at Function.exports.swig.render(/home/jamie/node_modules/consolidate/lib/consolidate.js:237:50)/ home/jamie/node_modules /巩固/ lib/consolidate.js:144:25 athome/jamie/node_modules/consolidate/lib/consolidate.js:97:5 at fs.readFile(fs.js:176:14)at Object.oncomplete(fs.js: 297:15)
在顶部,我这样设置
var express = require('express');
var cons = require('consolidate');
// assign the swig engine to .html files
console.log(cons.swig);
app.engine('html', cons.swig);
// set .html as the default extension
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
Run Code Online (Sandbox Code Playgroud)
然后我这样提出我的要求:
app.get('/', function(req, res){
res.render('home', {
title: "home"
});
});
Run Code Online (Sandbox Code Playgroud)
我在根目录/视图中有一个模板home.html
我的根目录是/ home/jamie/hello-world.我在这做错了什么?
编辑 顺便说一句,console.log(cons.swig)确实返回了一些内容.
{ [Function] render: [Function] }
Run Code Online (Sandbox Code Playgroud)
所以它绝对存在
在枝条本人具有操作员是与测试空变量(字符串或阵列):
{% if info is empty %}
...
{% endif %}
Run Code Online (Sandbox Code Playgroud)
我如何在Swig模板中做这样的事情?
我尝试过json过滤器,但是我发现"json"过滤器找不到错误.我做错了什么?
Error: Filter "json" not found at Object.exports.wrapFilter (......./node_modules/swig/lib/helpers.js:310:11)
<script type="text/javascript">
{{ places|json }}
</script>
Run Code Online (Sandbox Code Playgroud)
对象从mongodb传递
this.displayMainPage = function(req, res, next) {
"use strict";
places.getPlaces(10, function(err, results) {
"use strict";
if (err) return next(err);
return res.render('places_template', {
places: results
});
});
}
Run Code Online (Sandbox Code Playgroud)
编辑:我正在尝试输出json传递给谷歌地图并在html中显示相同的数据
所以我正在尝试使用consolidate.js来使用express 渲染swig模板,但是当我尝试从另一个模板中"扩展"一个模板时,我收到以下错误:
Error: ENOENT, no such file or directory '//one.html
Run Code Online (Sandbox Code Playgroud)
在我的app.js文件中,我将swig设置为我的渲染引擎(仅包含相关代码):
var consolidate = require('consolidate');
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.engine('.html', consolidate.swig);
app.get('/test', function(req, res) {
res.render('two');
});
Run Code Online (Sandbox Code Playgroud)
我有一个基本模板,one.html:
<h3>My Site</h3>
{% block content %}
Welcome
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
然后是一个继承模板,two.html:
{% extends 'one.html' %}
{% block content %}
This is an inner page.
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
那么为什么swig会寻找one.html一条路径//one.html(如上面的错误?)感谢您的帮助.
我正在用gulp监视某些文件并运行某些任务,但是在开始运行几次后,似乎停止监视了。如果在前两到五次更新后将html文件保存在pages目录中,则模板任务似乎停止运行。我已经在下面包含了我的gulpfile。
// Include gulp
var gulp = require('gulp');
// Include plugins
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var notify = require('gulp-notify')
var htmlv = require('gulp-html-validator')
var swig = require('gulp-swig');
var plumber = require('gulp-plumber');
// Linting
gulp.task('lint', function() {
return gulp.src('js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('sass', function() {
return gulp.src('./resources/scss/*.scss')
.pipe(sass()
.on('error', notify.onError(function(error) {
return 'Error: ' + error.message;
}))
)
.pipe(gulp.dest('./css'));
});
gulp.task('validate', function() {
return gulp.src('./**.html')
.pipe(htmlv({format: 'xhtml'}))
.pipe(gulp.dest('./validation_out'));
});
gulp.task('watch', function() {
gulp.watch('js/*.js', ['lint']);
gulp.watch('./resources/scss/*.scss', ['sass']);
gulp.watch('./pages/*.html', …Run Code Online (Sandbox Code Playgroud) 我正面临这个问题.
我有一个包含另一个这样的页面:
的index.html
{{ set pets = { pets : petsObject } }}
{{ include pets.html }}
Run Code Online (Sandbox Code Playgroud)
petsObject就是这样的对象
petsObjects: [
{ name : "cat" },
{ name : "dog" }
]
Run Code Online (Sandbox Code Playgroud)
当我尝试渲染页面时,我得到一个空白页面,只有这个:
[对象]
我不知道发生了什么:(
提前致谢!
我一直坚持看着我的Swig.js html模板并在每次更改时编译它们的问题,我为此目的使用Gulp.js任务运行器.这是我的gulpfile.js:
var gulp = require('gulp');
var myth = require('gulp-myth');
var swig = require('gulp-swig');
var nodemon = require('gulp-nodemon');
gulp.task('styles', function () {
gulp.src('./myth/*.css')
.pipe(myth())
.pipe(gulp.dest('./client/css'));
});
gulp.task('templates', function () {
gulp.src('./views/*.html')
.pipe(swig({ load_json: true }))
.pipe(gulp.dest('./client'));
});
gulp.task('server', function () {
gulp.run('styles');
gulp.run('templates');
gulp.src('./server.js').pipe(nodemon());
gulp.watch('./myth/*.css', function () {
gulp.run('styles');
});
gulp.watch('./views/*.html', function () {
gulp.run('templates');
});
});
Run Code Online (Sandbox Code Playgroud)
神话任务样式运行良好 - 每次更改myth/*.css我都得到更新文件client/css/..
但任务调用模板只给出一次结果..当我改变views/index.html文件时client/index.html保持不变.在我的控制台中,我看到模板 …
我正在尝试编写一个基于Express构建的行程应用程序.Swig是模板引擎.我对Swig的自动景观功能感到困惑.它到底是做什么用的?
Swig 文档示例:
"Control auto-escaping of variable output from within your templates."
// myvar = '<foo>';
{% autoescape true %}{{ myvar }}{% endautoescape %}
// => <foo>
{% autoescape false %}{{ myvar }}{% endautoescape %}
// => <foo>
Run Code Online (Sandbox Code Playgroud)
我的代码:
<script>
{% autoescape false %}
var all_hotels = {{ hotels | json }};
var all_restaurants = {{ restaurants | json }};
var all_things_to_do = {{ things_to_do | json }};
{% endautoescape %}
</script>
Run Code Online (Sandbox Code Playgroud)
谢谢.