0

试图围绕 Fatfree 以及如何使用数据库中的数据嵌套模板。到目前为止,我有一个加载三个模板的主页加载。到目前为止一切顺利,一切正常。

主班

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

主页.html

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

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

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

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

4

1 回答 1

1

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

<?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 }}" />
于 2021-02-07T02:47:04.853 回答