All add-ons currently require PHP 7.4 or greater.

On July 4th 2024 PHP 8.2 will be the new minimum requirement for all add-ons. Expect any add-on released after that date to require 8.2 or greater. Some releases may not immediately take advantage of 8.x specific features in PHP, which means you might, be able to continue using new releases in PHP 7.4, however, if you experience an error the first thing you should do is update to PHP 8.2 then create a support ticket if the error persists.

Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Escape is not escaping logged in check

Status Resolved
Add-on / Version Speedy 1.8.1
Severity
EE Version 7.3.14

Hop Studios

Nov 08, 2023

Hi Support,

I faced a very odd issue when implementing Speedy on my site. I wanted to show a segment of my channel entry tags only to the logged-in users. I wrapped that part in {exp:speedy:escape} tag, but that didn’t work as expected. Instead, the page was cached the same for the guest users as I wanted that to be cached for the logged-in users only. The escape tag escapes the logged in check when it is not used with the channel:entries tag. I can share the test code snippet for your reference if you want to, But the overall idea is that the escape tag has {if logged_in}  ... some text .. {/if} but that is shown for non-logged-in users too, if a page is cached in guest mode. The {if} tag doesn’t seem to be working under :escape tag if we wrap the channel entries tag around the Speedy fragment tag. 

I can share some more code snippet if you want to. Can you give me some more insights about this method of using the escape tag? How can I keep some bit non cached within a channel entry tag, and cache them.

Looking forward for your response.

Thanks!

#1

BoldMinded (Brian)

In this case I think you need to use the named escape tag, which apparently I didn’t document :(

Try something like this:

{exp:speedy:escape:is_logged_in}
        {if logged_in}
            Logged in
        {if:else}
            Not logged in
        {/if}
    {/exp:speedy:escape:is_logged_in}

This actually creates a global variable earlier in the parsing process and is able to do the replacement correctly.

#2

BoldMinded (Brian)

Actually I did have it documented, it’s the pre-escaping option: https://docs.boldminded.com/speedy/docs/tags#pre-escaping

#3

Hop Studios

Hi Brian, I had to re-open this ticket Thanks for the reply and sorry for the delayed reply. This tag works when I use without channel entries loop, but when I try to rap this under channel entries loop, it breaks. I want to show one of the fields ( {people_order} ) in a channel entries tag to the admin logged in users only -

{exp:speedy:fragment:admin_list} {exp:channel:entries channel=”people” orderby=”people_order” sort=”asc” dynamic=”off” {DISABLE}} <h3>{title} {if logged_in_primary_role_id == 1} {people_order} {/if} </h3> {/exp:channel:entries} {/exp:speedy:fragment:admin_list}

If this page is cached as a guest or non-admin users, the admin also doesn’t see the {people_order} field’s value, and if the page is cached as admin user, the guest/non-admin users see what they shouldn’t. I was looking for a solution under this situation.

Looking forward for your reply.

Thanks, Abhi

#4

BoldMinded (Brian)

This is the full template I tested it with and it worked as expected

{exp:speedy:fragment key="one"}
{exp:channel:entries channel="pages" limit="1"}
    {title}

    {exp:speedy:escape:is_logged_in}
        {if logged_in}
            Logged in
        {if:else}
            Not logged in
        {/if}
    {/exp:speedy:escape:is_logged_in}

{/exp:channel:entries}
{/exp:speedy:fragment}
#5

hopstudios

Yes, the text is shown, but if you refer to my code snippet again, you will see that we are trying to call a channel_field. It looks like the content under the escape tag is parsed earlier or after than the channel_entry tag is being parsed. We can’t even use ‘embed’ with it, because the same thing happens if we try to send entry_id to the ‘embed’ as a parameter.

Can you please take a look again with this context?

Thanks.

#6

BoldMinded (Brian)

That’s not going to work because the escaping removes it from the template before the entries tag parses.

#7

BoldMinded (Brian)

Or if it does parse then it puts back in the parsed value… either way it won’t work with a custom field like that.

#8

Hop Studios

Oh! This is what I have been asking. I tried doing that by repeating the entire code block. Can the add-on be extended to handle this requirement?

#9

BoldMinded (Brian)

I don’t think any sort of extension will change things…. it’s just how the parser works and I don’t think there is a way around this. You’ll probably have to have that one entries tag not be cached at all. Escape the whole entries tag, or load it’s contents with Ajax after the full page load.

#10

Hop Studios

I see. Thanks for your inputs. We can close this ticket.

Login to reply