【问题标题】:Two pages with the same layout different text相同布局的两个页面不同的文本
【发布时间】:2018-10-14 17:54:28
【问题描述】:

我想制作两个布局相同的页面,只是每个页面上的文本会有所不同。

我不想复制整页代码。我知道我可以使用 PHP 来包含布局,但文本需要不同。

【问题讨论】:

    标签: php html


    【解决方案1】:

    您可以使用模板引擎 (Jamsheed anwser) 或使用 php include()function。


    title.php

    Here is my site title

    content.php

    My website content

    然后你可以在你的网站中包含 title.php 和 content.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml"
      xml:lang="fr" lang="fr">
            <head>
              <title><?php include('titre.php'); ?></title>
    </head><body>
      <h1><?php include('content.php'); ?></h1>
    </body>
    </html>
    

    正如您所提到的,您的文本需要不同,例如,您可以在页面顶部使用if 语句来检查页面的获取参数并包含正确的页面 (https://localhost/website?article=home)

    我建议你看看this post,它解释了PHP 动态包含nPHP 动态内容

    【讨论】:

      【解决方案2】:

      您正在寻找的是模板引擎。 Here's a link 五个最好的 PHP 模板引擎(当然是基于意见的)。

      模板代理允许您指定要在多个页面中重复使用的页面部分,仅指定修改父模板的内容差异。我在上面发布的链接描述了一些最好的 PHP 模板代理,包括 Blade、Mustache、Smarty、Twig 和 Volt。其中大部分都易于使用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-15
        • 1970-01-01
        • 2012-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多