[英]Compiling html (headers and footers)
I'm about to start a small project involving creating a micro site. 我将开始一个涉及创建微型网站的小项目。 Typically I build my sites using a CMS system with a PHP backed such as WordPress however as the development for this site needs to be fast (and its only a few pages) we have opted to go with a static HTML site with some content generated by php (possible included via AJAX) for the time being.
通常,我使用带有WordPress等PHP支持的CMS系统来构建网站,但是由于该网站的开发需要快速(只有几页),因此我们选择使用静态HTML网站,该网站包含一些由php(可能通过AJAX附带)。
Now to my question, is there anyway to compile either before commit (using gulp/grunt or what have you) or on the server end? 现在我的问题是,无论在提交之前(使用gulp / grunt或您拥有什么)还是在服务器端都可以进行编译? Id like the site to take in separated headers and footers from various other files to help remove redundant code and ease maintenance.
我希望网站从其他文件中提取分开的页眉和页脚,以帮助删除多余的代码并简化维护。 Some sort of small template engine would do the trick.
某种小型模板引擎可以解决问题。 Can anyone point me in the correct direction?
谁能指出我正确的方向?
PHP is a template engine (amongst other things). PHP 是模板引擎(还有其他功能)。 There's no need for an external package.
无需外部包装。
An example: 一个例子:
<?php include 'path/to/header.html.php' ?>
<body>
<!-- put your page-specific contents here -->
</body>
<?php include 'path/to/footer.html.php' ?>
Update: 更新:
There's no standard way of doing client-side includes at the moment, although the idea was conceived a long time ago: http://en.wikipedia.org/wiki/Transclusion 尽管这个想法是很久以前构想的,但是目前尚无标准的客户端包含方法: http : //en.wikipedia.org/wiki/Transclusion
The closest thing in pure HTML are <iframe>
elements. 纯HTML中最接近的是
<iframe>
元素。
Using gulp, I'd go with something like gulp-concat: 使用gulp,我会使用gulp-concat之类的东西:
var gulp = require('gulp');
var concat = require('gulp-concat');
gulp.task('build-prototype', function() {
return gulp.src(['./src/header.html', './src/content.html', './src/footer.html'])
.pipe(concat('prototype.html'))
.pipe(gulp.dest('./dist/'));
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.