Header/navbar/footer 个元素未导入到新页面

Header/navbar/footer elements not importing into new page

我正在使用 UserFrosting,到目前为止,我已经能够将所有默认元素导入主页。但是,我现在添加了第二个页面,但是当我从主页复制以下代码时没有任何反应:

{% include 'common/components/head.html' %}
     <rest of code>
{% include 'common/components/main-nav.html' %}
     <rest of code>
{% include 'common/components/footer.html' %}   
{% include 'common/components/jumbotron-links.html' %}

然后我使用了以下 php 代码:

<?php include("../userfrosting/templates/common/components/head.html"); ?>

这似乎有效,但页面只显示在 head.html 文件中找到的代码:

{% for item in includeCSS(page_group|default("common")) %} {% endfor %} {% for item in includeJSTop(page_group|default("common")) %} {% endfor %} 

这显然不是很有用!

当我将主页和 page2.php 文件保存在同一文件夹中(在 localhost/userfrosting/templates/common 中)时,我收到错误 404。当我将文件移动到默认的 UserFrosting 主页目录( home.html file isn't actually in) in localhost/public, 我只得到上面的代码。

似乎我在这里遗漏了一些非常基本的东西,但希望得到一些帮助。谢谢

您混淆了 PHP 文件和模板文件。 UserFrosting 使用 front controller pattern along with the Twig 模板引擎。因此,您不需要为每个页面创建一个单独的 PHP 文件。相反,您应该为您的页面创建一个新的模板文件:

userfrosting/templates/common/page2.html

{% include 'common/components/head.html' %}
     // DO NOT use PHP here - just Twig!  See the Twig documentation: http://twig.sensiolabs.org/doc/templates.html
{% include 'common/components/main-nav.html' %}
     // More Twig
{% include 'common/components/jumbotron-links.html' %}
{% include 'common/components/footer.html' %}   

然后您需要使用此模板link创建一个URL。这是在 控制器 public/index.php 中完成的,例如:

// Miscellaneous pages
$app->get('/page2/?', function () use ($app) {    

    $app->render('common/page2.html', [
        'page' => [
            'author' =>         $app->site->author,
            'title' =>          "Page Deuce",
            'description' =>    "This is the second page, aight?",
            'alerts' =>         $app->alerts->getAndClearMessages()
        ]
    ]);          
});

我强烈建议阅读有关添加新页面的教程:https://learn.userfrosting.com/building-pages

您还可以在此处了解有关 MVC、Slim 和 Twig 的更多信息:https://learn.userfrosting.com/basics/overview

如果您仍有问题,欢迎加入chat