编译html(页眉和页脚)


Compiling html (headers and footers)

我即将开始一个涉及创建微站点的小项目。通常,我使用一个支持PHP的CMS系统来构建我的网站,比如WordPress。然而,由于这个网站的开发需要快速(而且只有几个页面),我们暂时选择了一个静态HTML网站,其中包含一些由PHP生成的内容(可能通过AJAX包含)。

现在我的问题是,在提交之前(使用gulp/grumt或其他方法)或在服务器端进行编译吗?我希望该网站从各种其他文件中提取独立的页眉和页脚,以帮助删除多余的代码并简化维护。某种小型模板引擎就可以做到这一点。有人能给我指正确的方向吗?

PHP一个模板引擎(除其他外)。不需要外部包装。

一个例子:

<?php include 'path/to/header.html.php' ?>
<body>
  <!-- put your page-specific contents here -->
</body>
<?php include 'path/to/footer.html.php' ?>

更新:

目前还没有标准的客户端include方法,尽管这个想法是很久以前就想到的:http://en.wikipedia.org/wiki/Transclusion

纯HTML中最接近的是<iframe>元素。

使用gullow,我会选择类似gullow-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/'));
});