编译html(页眉和页脚)

时间:2015-03-31 05:42:12

标签: php html templates gruntjs gulp

我即将开始一个涉及创建微型网站的小项目。通常我使用带有PHP支持的CMS系统(如WordPress)构建我的网站,但是由于此网站的开发需要快速(并且只有几页)我们选择使用静态HTML网站,其中包含一些由php(可能包括通过AJAX)暂时。

现在我的问题是,无论如何要在提交之前(使用gulp / grunt或者你有什么)或在服务器端编译?我喜欢网站从各种其他文件中分离页眉和页脚,以帮助删除冗余代码并简化维护。某种小型模板引擎可以解决这个问题。谁能指出我正确的方向?

1 个答案:

答案 0 :(得分:0)

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

一个例子:

<?php include 'path/to/header.html.php' ?>

<body>
  <!-- put your page-specific contents here -->
</body>

<?php include 'path/to/footer.html.php' ?>

<强>更新

目前没有标准的做客户端包含的方法,虽然这个想法是很久以前构思的:http://en.wikipedia.org/wiki/Transclusion

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

使用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/'));
});