doulin6761 2015-03-31 05:42
浏览 180

编译html(页眉和页脚)

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.

Now to my question, is there anyway to compile either before commit (using gulp/grunt or what have you) or on the server end? 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?

  • 写回答

1条回答 默认 最新

  • douxie1957 2015-04-05 23:11
    关注

    PHP is a template engine (amongst other things). 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

    The closest thing in pure HTML are <iframe> elements.

    Using gulp, I’d go with something like 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/'));
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line