dotj78335 2013-08-27 03:22
浏览 87
已采纳

Drupal 7 Views - 循环到$ fields并获取内容

So far, I have done the following things.

1 - created a view i called it (vue-du-galerie) with three fields (field_galerie_image,field__galerie_description,title)

2 - Created a custom theme as 'views-view-fields--vue-du-galerie.tpl.php'

3 - The block is working without a problem.

the html markup of the three fields :

        <div class="content-block-contact content-block-gallerie">
            <section class="slider">
                <div id="slider" class="flexslider">
                    <ul class="slides">
                    <!--(from here)loop between all the image fields -->
                        <li>
                            <img src="images/6.png" /> <!--field_galerie_image-->
                        </li>
                        <li>
                            <img src="images/6.png" /> <!--field_galerie_image-->
                        </li>
                        <li>
                            <img src="images/6.png" /><!--field_galerie_image-->
                        </li>
                    <!--(to here)-->
                    </ul>
                </div>
                <div id="carousel" class="flexslider">
                    <ul class="slides">
                    <!--(from here)loop between all the fields and make them like this -->
                        <li>
                            <div class="field-image-gallerie"><img src="images/6.png" /><!--field_galerie_image--></div>
                            <div class="field-titre-gallerie"><h1>Thématique 1<!--title--></h1></div>
                            <div class="field-description-gallerie"><p>Lorem upsom dolor i,setLorem Lorem upsom dolor i,set <!--field__galerie_descriptiont-->n</p></div>
                        </li>
                        <li>
                            <div class="field-image-gallerie"><img src="images/6.png" /><!--field_galerie_image--></div>
                            <div class="field-titre-gallerie"><h1>Thématique 1<!--title--></h1></div>
                            <div class="field-description-gallerie"><p>Lorem upsom dolor i,setLorem Lorem upsom dolor i,se <!--field__galerie_descriptiont--></p></div>
                        </li>
                    <!--(to here)-->
                    </ul>
                </div>
            </section>
        </div>

i tried this code in views-view-fields--vue-du-galerie.tpl.php but it it"s not working :

<div id="slider" class="flexslider">
    <ul class="slides">
        <?php foreach ($fields as $id => $field): ?>
            <li>
                <?php print $field['field_galerie_image']->content; ?>
            </li>
        <?php endforeach; ?>
    </ul>
</div>

<div id="carousel" class="flexslider">
    <ul class="slides">
        <?php foreach ($fields as $id => $field): ?>
            <li>
                <div class="field-image-gallerie"><?php print $field['field_galerie_image']->content; ?></div>
                <div class="field-titre-gallerie"><h1><?php print $title; ?></h1></div>
                <div class="field-description-gallerie"><p><?php print $field['field__galerie_description']->content; ?></p></div>
            </li>
        <?php endforeach; ?>
    </ul>
</div>
  • 写回答

1条回答 默认 最新

  • duanqiao1880 2013-08-27 08:29
    关注

    Maybe $field['YOUR_FIELD']->content is printing fields data with the extra markup added by views module.

    If that is the case, make sure that your view is printing only the field markup without any wrapper elements. From your view administration page admin/structure/views/view/VIEW_ID loop through all your fields.

    From Style settings; check Customize field HTML and Customize field and label wrapper HTML, and change the value of HTML element to - None -.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用