0

I keep running into issues using preload-replace with conditionals that are in a grid field.

I have the preload: {preload_replace:staticchannelslug="gp"}

And am trying to use it like so:

        {page_header_{staticchannelslug}}
            
            <h1>{if page_header_{staticchannelslug}:alt_title}...{if:else}...{/if}</h1>
            
        {/page_header_{staticchannelslug}}

This throws the error:

Something has gone wrong and this URL cannot be processed at this time.

EDIT:

Error with debug on:

You have an invalid conditional in your template. Please review your conditionals for an unclosed string, invalid operators, a missing }, or a missing {/if}.

Parser State: Unexpected ‘alt_title’ (VARIABLE); expected RD in Template “pages/general-page” on line 9.

//end edit

If I don't use the preload and change it to this, I get no errors:

        {page_header_gp}
            
            <h1>{if page_header_gp:alt_title}...{if:else}...{/if}</h1>
            
        {/page_header_gp}

I've used this same kind of method for years in EE2, but just running into issues with it in EE3 :/

This doesn't work either, same error message:

        {if '{page_header_{staticchannelslug}'}

            {page_header_{staticchannelslug}}
                            ...
            {/page_header_{staticchannelslug}}

        {/if}

Any ideas on what the issue is here or what I may be missing?

Thanks.

  • What error do you get when you are logged in as a Super Admin? Preload replacements are indeed what they say: simple text that is replaced throughout your template before it is executed, so I'd expect that to work. Though to be honest in the limited context above, I'm not understanding what you're gaining by doing do? – Derek Jones Jul 5 '16 at 17:03
  • "Something has gone wrong and this URL cannot be processed at this time." is the error I get when logged in as Super Admin. What I'm trying to achieve is just being able to reuse the code while just changing the slug in a preload (e.g.: a 'general page' channel field uses the slug "gp" but a 'blog post' channel field may use the slug "bp" - page_header_gp vs page_header_bp). Also, I've used this method to create a partial with the snippet, and then only have to change the slug variable per channel / template. Hope that makes sense! Really just usually a time-saver :) – ByteMyPixel Jul 5 '16 at 17:37
  • Yep, makes sense. Sounds like you have debug set to 0, as a logged in super admin you will get a more descriptive error. Make sure you do not have $debug set to 0 in your index.php, and your system settings has "Enable error reporting?" set to "yes". – Derek Jones Jul 6 '16 at 18:16
  • Ah yes, with debug on... I get this: You have an invalid conditional in your template. Please review your conditionals for an unclosed string, invalid operators, a missing }, or a missing {/if}. Parser State: Unexpected ‘alt_title’ (VARIABLE); expected RD in Template “pages/general-page” on line 9. I'll update my post to include this... – ByteMyPixel Jul 7 '16 at 16:16
  • Ok just verified the error on a fresh install, digging! – Derek Jones Jul 8 '16 at 20:11
1

This is an instance were you will need to quote your conditional, since it's not a true variable. Starting in version 2.9.0, the conditionals parser learned how to behave, and parses conditionals as soon as they are ready. Since what you have in the first example doesn't look like a valid variable, it doesn't know to wait for a value before evaluating it. In other words, since your variable is actually a string that you are putting together with other variables, you need to use:

{if '{page_header_{staticchannelslug}'}

That should be working for you, though you indicate it is not, and is working in my tests.

{preload_replace:replaced_var="image"}

....

{exp:channel:entries channel="blog"}
    {if "{blog_{replaced_var}:image}"}
        There's an image!
    {if:else}
        No image!
    {/if}
{/exp:channel:entries}

If you are still getting the error after following this pattern, reduce your template further to ensure you don't have a similar conditional somewhere else, in an embed, etc.

| improve this answer | |

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.