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.

dongnaoxia0927
dongnaoxia0927 看看twig.sensiolabs.org/doc/tags/include.html
接近 4 年之前 回复
doyou62860
doyou62860 你可以给出一个PHP代码的例子吗?
接近 4 年之前 回复
douyongdao4046
douyongdao4046 大概吧。@jmattheis
接近 4 年之前 回复
dry9192
dry9192 你想在twig文件中使用php吗?
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐