微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Fatfree 框架嵌套模板

如何解决Fatfree 框架嵌套模板

试图围绕 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 完成的,我现在就完成了。

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

解决方法

您可以将它们从数据库中提取出来并执行以下两项操作之一:

<?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 }}" />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。