douhuan6157 2016-04-13 14:17
浏览 78
已采纳

在许多页面上包含一个相同的html [关闭]

I have this html text on many pages

<head>
<meta charset="utf-8" name="viewport" content="width=device-width, height=device-height minimum-scale=1, maximum-scale=1">
<title>Account</title>
<link href="css/Master.css" rel="stylesheet"/>
    <link rel='stylesheet' media='screen and (max-width: 450px)' href='css/narrow.css' />
    <link rel='stylesheet' media='screen and (min-width: 451px) and (max-width: 800)' href='css/medium.css' />
    <link rel='stylesheet' media='screen and (min-width: 801px)' href='css/wide.css' />
</head>

The problem is that I want to use this same code for many pages without having to copy and paste over let's say 5 pages. Is there a clever way to use an "include" command for this?

  • 写回答

3条回答 默认 最新

  • dongxu2398 2016-04-13 14:23
    关注

    You can write a file with this:

    File with libs

     <meta charset='utf-8' name='viewport' content='width=device-width, height=device-height minimum-scale=1, maximum-scale=1'>
     <title>Account</title>
     <link href='css/Master.css' rel='stylesheet'/>
     <link rel='stylesheet' media='screen and (max-width: 450px)' href='css/narrow.css' />
     <link rel='stylesheet' media='screen and (min-width: 451px) and (max-width: 800)' href='css/medium.css' />
     <link rel='stylesheet' media='screen and (min-width: 801px)' href='css/wide.css' />
    

    HTML

    <head>
      <?php include("file_with_libs.php"); ?>
    </head>
    

    But I advise you that use a template engine like Twig. You have all information in: http://twig.sensiolabs.org/

    Or You can see other reply that i wrote, explaining how to use Twig: Best practices to create a Twig HTML Layout (Masterpage)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱