Extension, Module

Archived
Forum
(read-only)

CE Cache

ExpressionEngine 2, ExpressionEngine 3

Back to this add-on's main page
View Other Add-ons From Causing Effect

     

Escape tags being ignored.

Support (Resolved)

Jason Varga
Jason Varga

I’m hoping I’m missing something simple.

My {exp:ce_cache:escape} tag pair simply seems to be ignored.

Templates aren’t unusual.

{exp:ce_cache:it}
  {exp
:ce_cache:escape}
    {current_time format
="%g:%i:%s"}
  {
/exp:ce_cache:escape}
{
/exp:ce_cache:it} 

The time never changes.
When I look at the cached file through the CP, it shows the cached time, not the tag.

Causing Effect - Aaron Waldon
# 1
Developer
Causing Effect - Aaron Waldon

Hi Jason!

Escaping will escape pretty much everything it can with {exp..} tags and later in the parse order. If you would like to escape things with an early parse order too, like global variables, you’ll want to use pre escaping. Here’s an explanation from the Pre Escaping documentation:

If the Escape tag is given a unique tagpart (example: {exp:ce_cache:escape:blah}…{/exp:ce_cache:escape:blah} has a unique tagpart of blah) then its tagdata will be pre-escaped (escaped even before segment variables and globals are parsed) when using EE 2.4.0+.

I hope that helps. :)

Jason Varga
# 2
Jason Varga

That doesn’t seem to work, unfortunately.

Turns out the regular escape tags were working, for {exp:...} tags. I was just looking in the wrong spot, I guess.

The places it doesn’t work, specifically, are in code blocks like this:

{exp:ce_cache:it}
{exp
:ce_cache:escape:nav}
<ul>
  <
li {if segment_1 == 'about'}class="current"{/if}>About</li>
  <
li {if segment_1 == 'contact'}class="current"{/if}>Contact</li>
</
ul>
{/exp:ce_cache:escape:nav}
{
/exp:ce_cache:it} 

The conditionals are being parsed.
Is there any way to avoid that?

Causing Effect - Aaron Waldon
# 3
Developer
Causing Effect - Aaron Waldon

That doesn’t seem to work, unfortunately.

Hmm. Which version of ExpressionEngine are you using? My documentation erroneously said pre parse was available from EE 1.2.4+, but it should have been 2.4.0+.

The conditionals are being parsed.
Is there any way to avoid that?

One way to get the conditionals to parse later, would be to make them advanced conditionals (they are currently simple conditionals, which are parsed early):

<ul>
  <
li {if "{segment_1}" == 'about'}class="current"{/if}>About</li>
  <
li {if "{segment_1}" == 'contact'}class="current"{/if}>Contact</li>
</
ul
Jason Varga
# 4
Jason Varga

I’m using EE 2.5.5 and CE Cache 1.9.3

I changed the conditional to an advanced conditional like you suggested, but now my cached file looks like this:

<ul>
  <
li {if "actual value of segment 1" == 'about'}class="current"{/if}>About</li>
  <
li {if "actual value of segment 1" == 'contact'}class="current"{/if}>Contact</li>
</
ul

The same thing happens when I use {exp:ce_cache:escape} or {exp:ce_cache:escape:foo}

Causing Effect - Aaron Waldon
# 5
Developer
Causing Effect - Aaron Waldon

Can you please ensure that the CE Cache extension is installed?

Jason Varga
# 6
Jason Varga

It is.

Causing Effect - Aaron Waldon
# 7
Developer
Causing Effect - Aaron Waldon

Just to make sure I wasn’t losing my mind, I created a template with the following code:

{exp:ce_cache:it}
 
<p>This should be cached{current_time}</p>

 
{exp:ce_cache:escape:blah}
  
<p>This should not be cached{current_time}</p>
  <
ul>
   <
li {if segment_1 == 'about'}class="current"{/if}>About</li>
   <
li {if segment_1 == 'contact'}class="current"{/if}>Contact</li>
  </
ul>
 
{/exp:ce_cache:escape:blah}
{
/exp:ce_cache:it} 

When I look at the item in the CE Cache console in the View Item page, I see the following:

<p>This should be cached1365472595</p>

 
  <
p>This should not be cached{current_time}</p>
  <
ul>
   <
li {if segment_1 == 'about'}class="current"{/if}>About</li>
   <
li {if segment_1 == 'contact'}class="current"{/if}>Contact</li>
  </
ul

That looks like the desired outcome. I’m also running EE 2.5.5.

Is there another add-on that may be messing with the parse order, or something else that is going on in the template that may be preventing the expected results from being returned?

Jason Varga
# 8
Jason Varga

Stash.
...But then I removed Stash from the equation, just left the template with a single snippet. Same thing.
So, not Stash, I guess.

Then I placed the contents of the snippet in the template. It worked.

...Is there a special way I should be handling caching in snippets?

Causing Effect - Aaron Waldon
# 9
Developer
Causing Effect - Aaron Waldon

Is there a special way I should be handling caching in snippets?

Ah, you’re using a snippet. I guess that makes sense. When the template pre-parse hook is called, the snippet will simply show up as a template variable like, {sn_name}. The snippet’s contents are not displayed yet, so there is no way for the contents to be pre escaped. Later, the tag and its contents are parsed by EE. Since the data was not escaped, it will show.

I just added in pre-escaping for snippets and global variables. I’ll send over the beta for you to try out. :)

Jason Varga
# 10
Jason Varga

Sorry Aaron, I didn’t realize that snippets were a special use-case.
The beta that you sent works perfectly (using the extra tag part to trigger pre-escaping).

Thanks very much!

Causing Effect - Aaron Waldon
# 11
Developer
Causing Effect - Aaron Waldon

No problem, I didn’t know they were a special use case either. It makes sense though. Chicken and egg problem.

I’ll get the new version released in the next day or two. :) Thanks for your help and persistence, Jason.