1

I am having an issue with an embedded template. I embed the template passing a "type" variable. Then, in the embed file it displays the content based on which "type" was specified. This all works, but either the parse order or Assets is causing hundreds of extra assets sql queries and ignores simple "type" conditional. It looks like EE parse order states that embedded variables are parsed early, so I am not sure why I am getting output from within other conditionals? If I comment out my Assets 2 code it cuts out most (if not all) the extraneous requests. (from ~500 to a normal 100ish at the moment).

Below is the embedded template. If I uncomment the cottage_photos fields my display is correct but they ALL get parsed across the board regardless of "type" conditional or Assets 2 limit param. I am new to Stack Exchange, so sorry if the code formatting is incorrect.

UPDATE As I keep testing, I really think its Assets and not parse order. When I comment out all the custom assets fields (cottage_photos below) all the issues are resolved. So, the question is why are the assets fields ignoring parse order and limit param?

{!-- GRID VIEW -----------------------------------------------------------------}
{if "{embed:type}" == "grid"}

{exp:channel:entries channel="cottage-rentals" 
    dynamic="no" 
    status="open" 
    paginate="bottom"  
    limit="12" 
    orderby="title" 
    sort="asc" 
    disable="categories|member_data" 
    }

    {sn_pagination}

    {if count == 1}
        <ul id="cottage-grid" class="large-block-grid-4 small-block-grid-1">
    {/if}

    <li>
        <div class="cottage">
            <a href="{path='/accommodations/cottage-rentals/cottage'}/{entry_id}" class="leadin" title="Click here to view {title}">
                {!--exp:ce_img:single src="{cottage_photos limit="1"}{url}{/cottage_photos}" crop="yes" width="225" height="200" allow_scale_larger="yes"--}
                <strong class="title">{title}</strong>
            </a>
            <a href="#" title="Check availability (popup)"><i class="icon-calendar"></i>&nbsp;Check Availability</a><br>
            <a href="{path='/accommodations/cottage-rentals/cottage'}/{entry_id}" title="View details for rental {title}"><i class="icon-zoom-in"></i>&nbsp;View Details</a><br>
            <i class="icon-user"></i>&nbsp;{cottage_capacity}<br>
            <i class="icon-home"></i>&nbsp;{cottage_bedroom_count}<br>
        </div>
    </li>

    {if count == total_results}</ul>{/if}

{/exp:channel:entries}

{/if}

{!-- LIST VIEW -----------------------------------------------------------------}
{if "{embed:type}" == "list"}
{exp:channel:entries channel="cottage-rentals" 
    dynamic="no" 
    status="open" 
    paginate="bottom"  
    limit="25" 
    orderby="title" 
    sort="asc" 
    disable="categories|member_data" 
    }
    {sn_pagination}

    {if count == 1}
        <!-- Sortable table props: see http://www.datatables.net/ -->
        <table cellpadding="0" cellspacing="0" id="cottage-list-view">
            <thead>
                <tr>
                    <th>Gallery</th>
                    <th>Title</th>
                    <th>Capacity</th>
                    <th>Bedrooms</th>
                    <th>Preview</th>
                    <th>Details</th>
                </tr>
            </thead>
            <tbody>
    {/if}

    <tr>
        <td>
            {!--cottage_photos limit="1"}
                <a href="{url}" data-rel="{entry_id}" class="preview-modal">{exp:ce_img:single src="{url}" crop="yes" width="70" height="50" allow_scale_larger="yes" class="th"}</a>
            {/cottage_photos--}
        </td>
        <td><a href="{path='accommodations/cottage-rentals/cottage'}/{entry_id}"><strong>{title}</strong></a></td>
        <td>{cottage_capacity}</td>
        <td>{cottage_bedroom_count}</td>
        <td><a href="#" data-rel="{entry_id}" class="button preview-modal"><i class="icon-info-sign icon-large"></i>&nbsp;&nbsp;Preview</a></td>
        <td><a href="{path='accommodations/cottage-rentals/cottage'}/{entry_id}" class="button"><i class="icon-zoom-in icon-large"></i>&nbsp;&nbsp;View Details</a></td>
    </tr>

    {if count == total_results}</tbody></table>{/if}

{/exp:channel:entries}
{/if}

{!-- COTTAGE DETAIL VIEW ---------------------------------------------------------}
{if "{embed:type}" == "detail"}

{exp:channel:entries channel="cottage-rentals" 
    dynamic="no" 
    status="open" 
    paginate="bottom"  
    limit="1" 
    orderby="title" 
    sort="asc" 
    disable="categories|member_data|pagination" 
    {if embed:cottage_id}entry_id="{embed:cottage_id}" {/if}
    }

    <p><a href="{path='accommodations/cottage-rentals'}"><i class="icon-chevron-left icon-small"></i>&nbsp;more cottage rentals</a></p>
    <div class="row">

        <div class="large-4 columns">
            {!-- PHOTO GALLERY --}
            <div id="cottage-photos">
                {!--cottage_photos limit="21"}
                    {if count == '1'}
                        <a href="{url}" rel="group1" title="{desc}"><img src="{url}" width="100%" alt="{desc}" /></a>
                        <ul class="small-block-grid-4 large-block-grid-4">
                    {/if}

                    {if count > '1'}
                        <li>
                            <a href="{url}" rel="group1" class="cottage-thumb" title="{desc}">
                                {exp:ce_img:single src="{url}" crop="yes" width="160" height="122" allow_scale_larger="yes"}
                            </a>
                        </li>
                        {if count == total_results} 
                            </ul>
                        {/if}

                    {/if}
                {/cottage_photos--}
            </div>
        </div>

        <div class="large-8 columns">

            <div class="row">
                <div class="large-7 columns">
                    <h3>{title}</h3>
                    {cottage_description}
                    <h4 class="orange">Features</h4>
                    {cottage_features}
                    <h4 class="orange">Rooms Description</h4>
                    {cottage_rooms_description}
                </div>

                <div class="large-5 columns">
                    <div class="cottage-info-box">
                        <p><strong>Bedrooms:</strong> {cottage_bedroom_count}<br />
                        <strong>Capacity:</strong> {cottage_capacity}</p>
                    </div>
                    <h4 class="orange">Rental Rates</h4>
                    {cottage_rental_rates}
                </div>
            </div>

            {!-- MAP --}
            {if cottage_display_map == "Yes"}
                {if cottage_map_geocoded != ""}
                    <div style="clear:both; padding-top:10px;">
                        <h4>Location</h4>
                        {exp:gmap:init id="map" scrollwheel="false" style="width:100%;height:265px" latitude="{cottage_map_latitude}" longitude="{cottage_map_longitude}" map_type="google.maps.MapTypeId.ROADMAP"}
                        {exp:gmap:marker id="map" latitude="{cottage_map_latitude}" longitude="{cottage_map_longitude}" zoom="{cottage_map_zoom}" geocode="false"}{/exp:gmap:marker}
                    </div>
                {/if}
            {/if}

            {!-- AVAILABILITY --}
            {if cottage_rms_id != ""}
                <div style="clear:both; padding-top:28px;">
                    <h4>Availability</h4>
                    <div id="cottage-availability">
                        <iframe scrolling="no" src="http://rms5.resortplanet.com/1459/calendar.php?unit={cottage_rms_id}" style="border-style:hidden; width:100%; height:770px;"></iframe>
                    </div>
                </div>
            {/if}

        </div>
    </div>

    {if no_results}
        <h3>Lakeside Chautauqua Cottage Listings</h3>
        <p>Requested Cottage is no longer available or could not be found. Click here to return to <a href='{path="accommodations/cottage-rentals"}'>cottage rentals</a>
    {/if}
{/exp:channel:entries}

{/if}
  • S2D - what version of Assets and EE specifically are you on? And can you paste your template debugging and profiler output? – Lisa May 16 '13 at 22:11
2

Two things: you're quoting your embed variables in your conditionals, which actually makes them advanced conditionals. So first, instead of this:

{if "{embed:type}" == "list"}

Try this:

{if embed:type == "list"}

But second, and more importantly - just use Switchee. It is great at avoiding these parse order/performance issues.

{exp:switchee variable="{embed:type}" parse="inward"} {!-- < added end quote --}
    {case value="grid"}
        .. do your loop
    {/case}
    {case value="list"}
        .. do your loop    
    {/case}
{/exp:switchee}
| improve this answer | |
  • Thanks Derek. I had it that first way originally but I found another post where someone resolved the issue by doing it this way. Thanks for the tip on SwitchEE. I saw that, but I was trying to prevent adding yet another addon. I will post back after trying to switch and test. Thanks. – Shift2Design Apr 16 '13 at 19:11
  • Unfortunately that didn't resolve the issue. As soon as I uncomment the assets custom field hundreds of extra assets-related queries are made from within other type 'case' sections that aren't even matches. If I comment out the assets "cottage_photos" the queries drop to normal. – Shift2Design Apr 16 '13 at 20:00
  • Your code was missing a quote, once I added that it seems to isolate the crazy amounts of SQL calls to at least within the case statements. Now, as to why Assets is making a ridiculous amount of SQL statements I am not sure. – Shift2Design Apr 16 '13 at 20:18
  • 1
    Interesting. I did not know wrapping conditional parameters in quotes made it an advanced conditional. Crazy! – kmgdev Apr 17 '13 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.