如何使用内联代码在gsp页面中引入html代码段

时间:2014-06-17 12:45:13

标签: grails gsp

当i = 0或i = 4的值时,我想渲染下面的代码,以便我可以引入一行。

<%--<div class="row selected-classifieds">
--%>
<g:each in="${shortAds?}" var="item" status="i">
<%
    if(i==4 || i==0)
    out << '<div class="row selected-classifieds">'
     %>

<div class="col-lg-3">
        <div class="thumbnail">
            <%--<img src="http://placehold.it/800x600/e0e0e0" />--%>
            <img height=100, width=100
                src="${createLink(controller: 'ImageProcessing', action: 'DisplayImage', params: ['id': item.id])}" />

            <div class="caption">
                <p>
                    <small><a href="#"> ${item?.title}
                    </a></small>
                <p>
                <p>
                    <strong> ${item?.price}
                    </strong>
                </p>
            </div>
        </div>
    </div>
<%
    if(i==4 || i==0)
    out << '</div>'
    %>

</g:each>

它给出了以下错误消息。 URI:/ Classified / Class:org.codehaus.groovy.control.MultipleCompilationErrorsExceptionMessage:startup failed:C__SpringSource_ProjectClassified_Classified_grails_app_views_classified__adthumbnail_gsp:21:意外令牌:&lt; @第21行,第10栏。&lt;&lt; ^ 1错误

2 个答案:

答案 0 :(得分:2)

你可以尝试:

<g:each in="${shortAds?.collate(4)}" var="itemset">
    <div class="row selected-classifieds">
        <g:each in="${itemset}" var="item">
            <div class="col-lg-3">
                <div class="thumbnail">
                    <img height=100, width=100
                         src="${createLink(controller: 'ImageProcessing', action: 'DisplayImage', params: ['id': item.id])}" />
                    <div class="caption">
                        <p><small><a href="#"> ${item?.title}</a></small></p>
                        <p><strong>${item?.price}</strong></p>
                    </div>
                </div>
            </div>
        </g:each>    
    </div>
</g:each>

答案 1 :(得分:0)

感谢您的回答。这是我如何使用它。这是一种解决方法。它有效,但我有点不满意。

<div class="row selected-classifieds">

<g:each in="${shortAds?}" var="item" status="i">
    <g:if test="${ i  == 3}">
        <div class="row selected-classifieds">
    </g:if>

    <div class="col-lg-3">
        <div class="thumbnail">

            <img height=100, width=100
                src="${createLink(controller: 'ImageProcessing', action: 'DisplayImage', params: ['id': item.id])}" />
            <div class="caption">
                <p>
                    <small><a href="#"> ${item?.title}
                    </a></small>
                <p>
                <p>
                    <strong> ${item?.price}
                    </strong>
                </p>
            </div>
        </div>
    </div>
    <g:if test="${ i  == 3}">
        </div>
    </g:if>
</g:each>