php - 编译 html(页眉和页脚)

标签 php html templates gruntjs gulp

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

现在我的问题是,在提交之前(使用 gulp/grunt 或您有什么)还是在服务器端进行编译?我喜欢该站点从各种其他文件中获取单独的页眉和页脚,以帮助删除冗余代码并简化维护。某种小型模板引擎可以解决问题。谁能指出我正确的方向?

最佳答案

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

关于php - 编译 html(页眉和页脚),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29361350/

相关文章:

PHP 过早更新表

html - iframe src 是从用户的 ip 地址还是网站服务器的 ip 地址请求的?

mongodb - Meteor:订阅的集合不会自动更新( react 性)

c++ - 如何获取模板模板参数的模板参数?

php - 如何将 MYSQL 结果与 PHP 合并以获得漂亮的表格

PHP 文件未使用 jQuery/AJAX 触发

html - 带有固定宽度左右侧边栏的 flex 内部网格

html - 表单元素宽度

c++ - 将这些模板转换为别名声明

php - 如何从 html5 php 转换日期格式