Twitter bootstrap 将动态页脚添加到细枝文件

Twitter bootstrap 将动态页脚添加到细枝文件,twitter-bootstrap,twig,Twitter Bootstrap,Twig,我需要从我的一个php文件中获取数据(基本上我已经在那里编写了mysql查询),我想在TWIG文件(parent.html)中显示这些数据 以下是有关更多信息的代码。 这是parent.html,我需要在其中包含页脚 <!DOCTYPE html> <html> <head> <title>TEAM Aero: Your Commercial Jet Aircraft Trading Community</title>

我需要从我的一个php文件中获取数据(基本上我已经在那里编写了mysql查询),我想在TWIG文件(parent.html)中显示这些数据

以下是有关更多信息的代码。 这是parent.html,我需要在其中包含页脚

<!DOCTYPE html>
<html>
<head>
    <title>TEAM Aero: Your Commercial Jet Aircraft Trading Community</title>
    <meta content="text/html; charset=utf-8" http-equiv="content-type">
    <meta name="description" content="TEAM Aero: Your Commercial Jet Aircraft Trading Community" />
    <link rel="icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" type="text/css" href="/includes/css/grid-menu-style.css" />
    <link rel="stylesheet" type="text/css" href="/includes/css/grid-menu-style-responsive.css" media="screen and (max-width: 900px)"/>
    <script type="text/javascript" src="/includes/js/libs/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/includes/js/libs/knockout-3.0.0.js"></script>
    {% block extra_js %}
    {% endblock %}
</head>
<body>

<div class='header'>
    <div class="clearfix">

        <div style="float: left;">
            <a href="/controls/grid_menu/view.php">
                <img src="/images/grid_menu/biglogo.jpg" style="float:right;"/>
            </a>
        </div>
        <div class="header-right-block">
            {% if globals.user.id %}
                <div class="header-image-wrapper">
                {% if globals.user.image %}
                    <img src="/files/user_photos/{{ globals.user.image }}" style="max-height: 100px; max-width: 100px;">
                {% else %}
                    <img src="/images/icon_no_photo_80x80.png" style="height: 100px; width: 100px;">
                {% endif %}
                </div>
            {% else %}
                <a href="/auth/login.php">
                    <div class="header-login-wrapper">
                        <div class="header-right-block-text">LOG IN</div>
                    </div>
                </a>
            {% endif %}
        </div>
    </div>
</div>

<div style="width:97%;margin: auto;padding-top:15px;">
    <a href="http://www.pw.utc.com/DependableServices" target="_blank">
        <img src="/images/grid_menu/PW-Services_Distance_600x100.jpg" style="width:100%;text-align:center;">
    </a>
</div>

<div id="user-info" data-role-id="{{ globals.role_id }}"></div>

<div class="free-wall grid-menu-container">
    {% block content %}
    {% endblock %}
</div>

{% include "grid_menu/footer.html" %}
</body>
</html>

航空团队:您的商用喷气式飞机交易社区
{%block extra_js%}
{%endblock%}
{%if globals.user.id%}
{%if globals.user.image%}
{%else%}
{%endif%}
{%else%}
{%endif%}
{%block content%}
{%endblock%}
{%include“grid_menu/footer.html”%}
下面的代码是包含查询的footer.php

<?php

require_once("../../bootstrap.php");

$menus = Doctrine_Query::create()
    ->from("GridMenu")
    ->where("position = ?", array(12))
    ->orwhere("position = ?", array(11))
    ->orwhere("position = ?", array(10))
    ->orderBy("position ASC")
    ->execute();

$menusMap = array();
foreach($menus as $menu){
    if(empty($menusMap[$menu->position])){
        $menusMap[$menu->position] = array();
    }
    $menusMap[$menu->position][] = $menu;
}


foreach($menusMap as $menuPosition => $menusArray) {

    if($menuPosition == 0){

        continue;
    }
    //shuffle($menusArray);
    $menu = $menusArray[0];

    $block[$menuPosition]['image_path']= $menu->image_path;
    $block[$menuPosition]['url']= $menu->url;
} 
echo $twig->render('grid_menu/footer.html', array(
    "user" => User::getCurrent(),
    "menusMaps" => $block
));

?>

这是用twig编写的footer.html

{% block footer %}

<div class='footerAd'>
{% for key, menusMap in menusMaps %}
<a href='{{ menusMap.url|e }}' target='_self'><div class='cell' style='background-image: url(/images/grid_menu/{{ menusMap.image_path|e }});background-size:100% 100%;float:left;position:relative;margin:20px'></div></a>
{% endfor %}
</div>


<div class='header' style="clear:both">
    <div class="clearfix">
        <div class="float-left">

            <br>
            <br>
        </div>
    </div>
</div>

{% endblock %}
{%block footer%}
{%用于键,menusMaps%中的menusMap}
{%endfor%}


{%endblock%}
在result parent.html中没有显示数据库结果,我想在parent.html中显示页脚内容,尽管它显示的是div,但不是查询结果

我是个新手,你的小小帮助可以帮我解决大问题

提前感谢。

正如您所说,您的代码是“显示div,但不显示查询结果”。这意味着
{%include“grid\u menu/footer.html”%}
确实正在访问
grid\u menu/footer.html
。查询结果未显示,因为您尚未执行查询。您所做的只是包含
footer.html
,但没有执行
footer.php

如果您使用的是Symfony,那么可以通过实现它所称的功能来自动实现。从您的代码结构来看,我假设您没有使用Symfony。没关系

我会给你一个非常简单的解决方案,尽量不要改变太多的代码。这里的主要问题是因为
{%include“grid\u menu/footer.html”%}
。通常,您应该包含
footer.php
,但twig不允许这样做,除非您使用twig扩展,例如函数:

$function = new Twig_SimpleFunction("render", function ($phpFile) {
   include $phpFile;
}, array('is_safe' => array('html')));

$twig->addFunction($function);
现在,定义了此函数“
render
”,您可以使用:

{{ render("footer.php") }}
而不是:

{% include "grid_menu/footer.html" %}
请允许我评论一些与问题无关的东西,但我不能不说:您可以使用
,其中
函数,而不是使用位置参数,如下所示:

$menus = Doctrine_Query::create()
    ->from("GridMenu")
    ->whereIn("position", array(10, 11, 12))
    ->orderBy("position ASC")
    ->execute();
如果你在台阶上卡住了,请告诉我。我很乐意帮忙


希望有用

你会犯什么错误?嗨,非常感谢!但是你能告诉我..我应该在哪里添加那个小树枝扩展,还有$phpFile指的是什么吗?是的,我也是新来的..谢谢你的帮助!:)@PHP:My荣幸:)$phpFile指的是要呈现的PHP文件。细枝扩展名为“render”,它是一个允许一个参数$phpFile的函数。当您执行{render(“footer.php”)}时,您正在调用细枝扩展函数“render”,并将“footer.php”作为参数传递。@php:您可以在包含细枝库的同一文件中添加细枝扩展名。如果您仍然停留在这一步,请在这里发布您的文件的层次结构,以及您在哪里包含了细枝库,我将详细介绍。