Fatfree 框架嵌套模板

Fatfree Framework nested Templates

尝试思考 Fatfree 以及如何使用数据库中的数据嵌套模板。 到目前为止,我有一个加载三个模板的主页。到目前为止还不错,一切正常。

主要class

function homePage($f3){
   $f3->set('slider','slider.html');
   $f3->set('testimonials','testimonials.html');
   $f3->set('cardContainer','cardContainer.html');
   echo Template::instance()->render('home.html');
}

Home.html

<include href="{{ @slider }}" />
<include href="{{ @testimonials }}" />
<include href="{{ @cardContainer }}" />

CardContainer 需要加载包含存储在数据库中的图像和其他文本的卡片。我可以从数据库中获取这些行,在 Main class 和 var_dump 中没有问题,它们到视图中。

我怎么不明白我是如何将该数据添加到卡片模板,然后将该卡片插入到 cardContainer 中的?我什至不确定我需要寻找什么才能使这成为可能。任何方向都会很受欢迎。如果这是直接完成的PHP我现在就完成了。

感谢您提供的任何帮助或指导。

您可以将它们从您的数据库中拉出并执行以下两件事之一:

<?php
// option 1
function homePage($f3){
   $cards = $f3->db->getYourCardsOrWhatever();
   $f3->set('cards', $cards);
   $f3->set('slider','slider.html');
   $f3->set('testimonials','testimonials.html');
   // then in here you would reference @cards in a <repeat> element
   $f3->set('cardContainer','cardContainer.html');
   echo Template::instance()->render('home.html');
}

// option 2
?>
<include href="{{ @slider }}" />
<include href="{{ @testimonials }}" />
<include href="{{ @cardContainer }}" with="cards={{ @cards_from_somewhere_to_inject }}" />