layout模版布局


存放位置

主题下面,如“default主题下面有个default layer”

  1. /template/default/default.layer.php

怎样加载共用模版

比如要加载共用的头部,我们可以直接在模版里面这样写,这样就载入了当前主题下面Public/header.tpl.php如:/template/default/Public/header.tpl.php

  1. <?php $this->_loadFile('Public/header.tpl.php') ?>

原理

  1. <?= $this->_loadContent(); ?>

给出一个layout模版例子

  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="keywords" content="<?= $this->metaKeywords(); ?>" />
  6. <meta name="description" content="<?= $this->metaDesc(); ?>" />
  7. <link rel="stylesheet" href="<?= $this->staticRes('css/base.css'); ?>">
  8. <link rel="stylesheet" href="<?= $this->staticRes('css/common.css?v=1.0.2'); ?>">
  9. <link rel="stylesheet" href="<?= $this->currentCss(); ?>">
  10. <title><?= $this->title ?> - TimoPHP</title>
  11. </head>
  12. <body>
  13. <header class="header">
  14. <div class="wrap">
  15. <div class="con">
  16. <a class="logo fl" href="/"><img src="<?= $this->res('images/logo.png'); ?>" /></a>
  17. <ul class="nav fl">
  18. <?php foreach($this->data['nav'] as $item): ?>
  19. <li><a href="<?= $this->link($item['url']) ?>"<?= $this->data['current_nav'] == $item['url'] ? ' class="on"' : '' ?>><?= $item['name'] ?></a></li>
  20. <?php endforeach; ?>
  21. </ul>
  22. <a class="avatar fr" href="<?= $this->link('member'); ?>"><img src="<?= $this->res('images/avatar.jpg'); ?>" /></a>
  23. </div>
  24. </div>
  25. </header>
  26. <?= $this->_loadContent(); ?>
  27. <footer class="footer">
  28. <p>
  29. <a href="">关于我们</a> |
  30. <a href="">联系我们</a> |
  31. <a href="">用户条款</a> |
  32. <a href="">隐私申明</a> |
  33. <a href="">加入我们</a>
  34. </p>
  35. <p class="fs12">Powered by <a target="_blank" title="开源社区" href="http://www.timophp.com/">TimoPHP</a> 1.2 Copyright © 2016 - 2020 <a target="_blank" href="http://www.timophp.com/">TimoPHP</a> 蜀ICP备08335298号</p>
  36. </footer>
  37. </body>
  38. </html>