我使用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"); ?>
这似乎工作,但页面只显示在header .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。当我将文件移动到localhost/public中的默认UserFrosting主页目录(home.html文件实际上不在其中)时,我只得到上面的代码。
似乎我在这里错过了一些非常基本的东西,但会感谢一些帮助。谢谢。
你混淆了PHP文件和模板文件。UserFrosting使用前端控制器模式和Twig模板引擎。因此,您不需要为每个页面创建单独的PHP文件。相反,您应该为您的页面创建一个新的模板文件:
userfrosting/模板/共同/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' %}
然后你需要链接一个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