Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

My Stash template has the following:

{if "{member_images:total_rows}" == 0}
    {!-- No images uploaded. Display placeholder as avatar. --}
    <img class="img-polaroid" src="http://placehold.it/133x100/" alt="No image uploaded"/>
{/if}
{if "{member_images:total_rows}" == 1}
    {!-- Only one image uploaded. Display that image as avatar. --}
    {member_images}
        <img class="img-polaroid" src="{member_image:133x100}" alt="{caption}"/>
    {/member_images}
{/if}
{if "{member_images:total_rows}" > 1}
    {if "{member_images:total_rows search:default="y"}" == 0}
        {!-- Multiple images upload, but none defined as default. Display first image as avatar. --}
        {member_images limit="1"}
            <img class="img-polaroid" src="{member_image:133x100}" alt="{caption}"/>
        {/member_images}                            
    {/if}                           
    {if "{member_images:total_rows search:default="y"}" == 1}
        {!-- Multiple images upload, and one defined as default. Display that image as avatar. --}                              
        {member_images search:default="y"}
            <img class="img-polaroid" src="{member_image:133x100}" alt="{caption}"/>
        {/member_images}                            
    {/if}
{/if}

This works fine. However, since I need this in different parts of my site, I figured I'd pull it out into its own stash template and just try to embed it where ever it's needed, like this:

{stash:embed name="common:.avatar" process="start"}

The problem is when I do this, nothing is outputted. When I enabled template debugging, I see the following error:

Parse error: syntax error, unexpected T_STRING in /home/devserver/public_html/system/expressionengine/libraries/Functions.php(683) : eval()'d code on line 12

I have no problems embedding other stash templates. Any ideas what might be wrong?

UPDATE 1:

The culprit seems to be the nested if block, particularly the if-conditions (e.g. {if "{member_images:total_rows search:default="y"}" == 0}. The if-condition contains a tag that must first be parsed? I'm guessing this might have something to do with parsing order, etc.?

UPDATE 2:

Currently using this code now. Incorporated elseif, single quote wraps tag when tag has double quote, etc.

{if "{member_images:total_rows}" == 0}
    {!-- No images uploaded. Display placeholder as avatar. --}
    <img class="img-polaroid" src="http://placehold.it/133x100/&text=No Image" alt="No Image"/>
{if:elseif "{member_images:total_rows}" == 1}
    {!-- Only one image uploaded. Display that image as avatar. --}
    {member_images}
        <img class="img-polaroid" src="{member_image:133x100}" alt="{caption}"/>
    {/member_images}
{if:elseif "{member_images:total_rows}" > 1}
    {if '{member_images:total_rows search:default="y"}' == 0}
        {!-- Multiple images uploaded, but none defined as default. Display first image as avatar. --}
        {member_images limit="1"}
            <img class="img-polaroid" src="{member_image:133x100}" alt="{caption}"/>
        {/member_images}                                                    
    {if:elseif '{member_images:total_rows search:default="y"}' == 1}
        {!-- Multiple images uploaded, and one defined as default. Display that image as avatar. --}                                
        {member_images search:default="y"}
            <img class="img-polaroid" src="{member_image:133x100}" alt="{caption}"/>
        {/member_images}                            
    {/if}
{/if}
share|improve this question
1  
Maybe as the condition you're testing is consistent use switchee with a parse="inward" will yield better results. I to struggle with parse order but one day we'll have our light bulb moment ;-) –  stuartmcd69 Jan 6 '13 at 10:36
2  
When you include a stash template with process="start" it simply reads the template file (or its cache) and replaces the embed tag with the contents of the file. The host template is then parsed as usual by EE. Functionally this is equivalent to using a snippet. Please try this first: instead of a Stash embed, make the code block a snippet. Do you get the same error? Second, try making the change I described in the EE forum. This still looks like a conditionals bug to me. –  Mark Croxton Jan 7 '13 at 15:09
1  
You need to strike a balance between staying DRY and performance. Long nested chains of embeds sounds like overkill to me; if you have code that is common to all or most of your site then encapsulate it in a snippet not an embed (whether EE or Stash), since all snippets are loaded with a single query rather than a query for each embed. Snippets can be managed as files (using one of the various add-ons that do this) so you don't lose anything. At the least your 'main stash file' mentioned above should be snippet if every template uses it. –  Mark Croxton Jan 7 '13 at 15:41
1  
If you set parse_stage="set" on the first (parent) Stash embed, and providing you have set stash_file_sync= FALSE in your config, then all child nested embeds will be compiled into a single cached record. That still doesn't mean what you're doing is a good idea though - see my comments here: expressionengine.stackexchange.com/questions/3555/… –  Mark Croxton Jan 10 '13 at 18:59
2  
Mark, just a thought. You are of course the Stash expert, and you give such excellent answers to every way people try to apply it. I would just like to suggest that you post as 'Answer', so that our EE StackExchange reckons the answers. This is important for getting the site past Beta according to StackExchange rules. I thought you might be going with comments to have proper conversations; appreciate that well, and also think you can do that with comments off your answer or indeed also off the original. Hope sounds good to you, and thanks for Stash, especially. –  narration_sd Feb 19 '13 at 19:53
show 15 more comments

1 Answer 1

up vote 2 down vote accepted

This is one of those questions where an enormous amount of good information has been posted by an expert - in this case the designer of the plugin/s in question.

Given that the solution suggested involves simplification of the original design, and as the conversation's then gone quiet, I am going to follow a tweeted idea to make our StackExchange 'unanswered' space more actionable, and suggest that there's an answer, within the main comment thread.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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