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条回答

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!