duannue2455 2016-11-20 09:43
浏览 67

PHP,Slim,twig模板,不能在主模板中使用PHP?

Basically I have one file, which is my "base"/"main" template, base.php.

It's pretty much my whole site, and I'd then like to have for example forum.php, profile.php that would simply extend these, using {% extends base.php %}.

Problem is, I would like to parse news/blog posts, sidebar with members area (depending if they're logged in or not) etc. inside my base.php.

Sadly twig doesn't seem to parse it, and if I understand correctly, I'd have to do:

echo $twig->render("home.php", array('news' => $newsArr, 'user' => $userArr, 'blogs' => $blogArr', 'forumPosts' => $forumArr));
echo $twig->render("forum.php", array('news' => $newsArr, 'user' => $userArr, 'blogs' => $blogArr', 'forumPosts' => $forumArr));
echo $twig->render("profile.php", array('news' => $newsArr, 'user' => $userArr, 'blogs' => $blogArr', 'forumPosts' => $forumArr));
echo $twig->render("blogs.php", array('news' => $newsArr, 'user' => $userArr, 'blogs' => $blogArr', 'forumPosts' => $forumArr));
echo $twig->render("about.php", array('news' => $newsArr, 'user' => $userArr, 'blogs' => $blogArr', 'forumPosts' => $forumArr));

(No idea why I use the .php extension since I can't use PHP in neither the "main" template, nor in my file extending the "main" template) As in.. - I'd have to pass all arrays for the sidebars etc, EVERY time, to then render template I want to use to extend my main template with?

Why can I not just use PHP tags within my base.php, and have my sidebars taken care of?

Tired as hell right now, I'll re-write it if it's hard to understand what I'm trying to say.

I use Slim Framework together with Twigs template engine.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
    • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
    • ¥15 知识蒸馏实战博客问题
    • ¥15 用PLC设计纸袋糊底机送料系统
    • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
    • ¥15 用C语言输入方程怎么
    • ¥15 网站显示不安全连接问题
    • ¥15 51单片机显示器问题
    • ¥20 关于#qt#的问题:Qt代码的移植问题
    • ¥50 求图像处理的matlab方案