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条)

报告相同问题?

悬赏问题

  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题