I’ve discovered a tricky question about parse order and low variables I’ve run into. This is a code base I’ve inherited, so I’m not sure how best to handle. (My apologies in advance; I am neither an EE nor a LV expert.) Any thoughts you have would be much appreciated.
Template pseudocode:
{if segment_2 ==“books”}
{Generate list of books here—lots of heavy SQL}
{if no_results}
sorry, no books found
{/if}
{lv_classic_display} // This is a template for what we want to display for each book
{/if}
{if segment_2 == “authors”}
... same as above, but SQL pulls up authors
{if segment_3 == “publishers”}
... same as above, but SQL pulls up publishers
The problem I’m having is that the SQL stuff is being executed for ALL options on the page. So, even if my segment_2 = “publishers”, it is still running the full SQL for pulling up all authors, and for pulling up all books, in addition to for publishers. The stuff is never displayed on the page, because of the IF statements in there, but the SQL is causing a major performance drag. It’s running hundreds of unnecessary queries in the background.
If I remove the {lv_classic_display}, the SQL does not execute. So it appears to me that the inclusion of the low variable is forcing the loop around it to execute BEFORE the IF statement.
Early Parsing is turned on on the site—and I don’t think I can turn that off. Is there a way for me to modify this to prevent this?
I have tried using the alternate syntax:
{exp:low_variables:parse var=“lv_classic_display”}
and while that DOES eliminate the database queries, it also outputs just the { } code, rather than executing it. So for each book my output looks like this:
{ml_author_name}
{ml_screen_name}
Any suggestions for how I might be able to adjust this? The performance on this page is getting killed by these silent SQL queries running in the background that aren’t ever going to get displayed….
Thank you very much.
Dave V.