duanbiao4025 2013-01-04 13:10
浏览 34
已采纳

php模板和html整洁[关闭]

Would this technically pass as a basic level template system in php?

So there are two files, index.php and Template_Module.php

Here is index.php code

<?php

include("Template_Module.php");

$set_name = "My Website";
$set_desc = "My Website for random bla bla";
$set_key  = "site, random, bla, for";

echo template_header_object($set_name, $set_desc, $set_key);

and here is Template_Module.php code

<?php

function template_header_object($set_title, $set_desc, $set_keywords) {

     $title_object = htmlspecialchars($set_title);    //lets get html title to pass
     $desc_object  = htmlspecialchars($set_desc);     //lets get meta description to pass
     $keyw_object  = htmlspecialchars($set_keywords); //lets get meta keywords to pass

     $template_create_object .= <<<OBJECT
<!doctype html>
     <html>
         <head>
             <meta charset="utf-8">
                 <title>$title_object</title>
    <!-- general meta -->
             <meta name="description" content="$desc_object">
             <meta name="keywords" content="$keyw_object">

    <!-- mobile specific meta -->
             <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">           

    <!-- open graph meta -->
             <meta property="og:title" content="$title_object">
             <meta property="og:image" content="/assets/img/logo_fbtype.png">
             <meta property="og:site_name" content="$title_object">
             <meta property="og:description" content="$desc_object">

    <!-- style sheets and scripts -->
             <link href="/assets/css/style.css" rel="stylesheet">
             <link href="/assets/css/reset.css" rel="stylesheet">
             <link href="/assets/img/favicon.png" rel="shortcut icon">

                <!--[if lt IE 9]>
                <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
                <![endif]-->

             <script src="http://code.jquery.com/jquery-latest.js"></script>
         </head>
     <body></body></html>        
OBJECT;

     return $template_create_object;

}

And is there a way I can improve the way html is rendered to browser, so the source code looks nicer instead of being completely off from how it looks at $template_create_object .= <<<OBJECT and is there a better way for passing values from index.php to template_object.php

  • 写回答

1条回答 默认 最新

  • dongsunny1113 2013-01-04 14:51
    关注
    1. Yes, it's a perfectly good way of doing a basic template in PHP. It's very basic, and doesn't offer much flexibility, but it's a quick and easy starting point. If you don't need anything more complex, it'll suit you fine. (If you do need something more complex, there are plenty of open source PHP templating packages you can use)

    2. Seriously, don't worry about how the finished HTML code looks. You shouldn't need to look at it anyway (If you need to debug it, use the browser's DOM view; it's a much easier way to work with it than viewing the source, even if the source if neat and tidy).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)