5

With the overall goal of reducing page load time (Memory, Execution Time in template debugging), how can I rework my Playa templates so as to “shut off” the Playa Extension?

Template debugging shows that I have 511 lines like so:

Calling Extension Class/Method: Playa_ext/channel_entries_tagdata

(The largest batch of them, 435 at a stretch, adds 3 seconds and 5MB to page execution time. And of course those 511 lines of calls appear on a section of the site that isn't using Playa. I've already gotten rid of similar calls for Matrix and P&T Field Packs by downloading the latest Field Pack off Github)

In this (old) P&T Support discussion thread, Brandon Kelly mentions that it's possible, by adding A Thing Or Two to your Playa tags, to disable the Playa extension. (I've done that with Matrix and, Field Pack, thanks to the latest version of them)

Brandon:

You’d just have to remember to set entry_id="{entry_id}" on any Playa tags inside {exp:channel:entries}, as well as set the var_prefix= param:

{exp:playa:children field="some_field" entry_id="{entry_id}" var_prefix="child"}
  {child:title}
  ...
{/exp:playa:children}

How do I apply that in this situation where I have a matrix tag pair and all that image replacement stuff going on?

{exp:channel:entries 
    channel="thankyou" 
    orderby="date" 
    sort="desc" 
    limit="1"
}
<h2>Thank you {title}</h2>
{thanks_body}

{!-- Playa Field tag pair: --}
{thanks_related_entries limit="8"} 

<div class="related blurb">
{exp:lg_replace:haystack needles="{mtrx_images backspace="1"}image_{row_count}|{/mtrx_images}"}

<h4>
{if channel_id=="1"}<a href="/news/view/{url_title}">{/if}
{if channel_id=="4"}<a href="/articles/view/{url_title}">{/if}
{title}</a> </h4>

<p class="excerpt">
    {exp:eehive_hacksaw words="55" append="&#8230;"}
        {exp:smartdown} {summary} {body} {/exp:smartdown}
    {/exp:eehive_hacksaw}

{mtrx_images}    
    {exp:lg_replace:replacement needle="image_{row_count}"}
        <a href="{img}" title="{img-caption}">{exp:ce_img:single src="{img}" width="70" alt="{img-caption}" class="left" title="{img-caption}"}</a>
    {/exp:lg_replace:replacement}   
{/mtrx_images}
</p>
<p class="excerpt smallcaps">{if channel_id=="1"}<a href="/news/view/{url_title}">{/if}{if channel_id=="4"}<a href="/articles/view/{url_title}">{/if}&raquo; Read This</a></p>
{/exp:lg_replace:haystack} 
</div>
{/thanks_related_entries}

Used in a similar manner in another location, I've wrapped the entire playa tags inside an if statement:

{if static_playa_related_posts}
    {static_playa_related_posts limit="15"}
     ...STUFF....
     {/static_playa_related_posts}
{/if}
3

Here is what worked. Discussion follows below the code.

{exp:playa:children 
    field="static_playa_related_posts"
    entry_id="{entry_id}"
    var_prefix="child"
    limit="8" 
    }
<div class="related blurb">
{exp:lg_replace:haystack needles="{child:mtrx_images backspace="1"}image_{row_count}|{/child:mtrx_images}"}

<h4><a href="{child:comment_url_title_auto_path}">{child:title}</a> </h4>

<p class="excerpt">
    {exp:eehive_hacksaw words="55" append="&#8230;"}
        {exp:smartdown} {child:summary} {child:body} {/exp:smartdown}
    {/exp:eehive_hacksaw}

{child:mtrx_images}    
    {exp:lg_replace:replacement needle="image_{row_count}"}
        <a href="{img}" title="{img-caption}">{exp:ce_img:single src="{img}" width="70" alt="{img-caption}" class="left" title="{img-caption}"}</a>
    {/exp:lg_replace:replacement}   
{/child:mtrx_images}
</p>
<p class="excerpt smallcaps right"><a href="{child:comment_url_title_auto_path}">&raquo; Read This</a></p>

{/exp:lg_replace:haystack} 
</div>

{/exp:playa:children}

The matrix field tag pair {mtrx_images} {/mtrx_images} both got the child: prefix in both places where they were used. {child:mtrx_images} {/child:mtrx_images}

The matrix field's contents did NOT have any prefix applied.

The {if channel_id=="1"} set of statements did not survive this method, tho. Instead, I used {comment_url_title_auto_path} and gave it the prefix. {child:comment_url_title_auto_path}

Finally, for the example where everything was wrapped by a conditional, the IF used the name of the playa field, and the more detailed exp:playa:children markup went inside it:

{if static_playa_related_posts}

{exp:playa:children 
    field="static_playa_related_posts"
    entry_id="{entry_id}"
    var_prefix="child"
    limit="15" 
    }

.......

{/exp:playa:children}
{/if}

Then I uninstalled the Playa extension (but kept the Field Type and Module installed)

Memory usage on the original page:

BEFORE 28 MB (30,207,216 bytes)
AFTER 19.5 MB (20,432,320 bytes)

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.