croxton / Stash

Stash allows you to stash text and snippets of code for reuse throughout your templates.
GNU General Public License v3.0
197 stars 20 forks source link

The following tag has a syntax error: {exp:exp:channel:entries} after upgrading to Stash 3.0.9 #168

Closed tyssen closed 4 years ago

tyssen commented 4 years ago

I've just upgraded a site that was on Stash 3.0.6 (EE 5.3.2) to 3.0.9 and now get The following tag has a syntax error: {exp:exp:channel:entries} on every page.

The site is set up like this:

{stash:embed
    name="home"
    file_name="views:home"
    process="static"
    logged_out_only="yes"
}

I upgraded to 3.0.9 because I was getting this error when debugging was on:

Warning count(): Parameter must be an array or an object that implements Countable user/addons/stash/mod.stash.php, line 843

croxton commented 4 years ago

Looks like you have an extra 'exp:' somewhere in your templates? {exp:exp:channel:entries} ?

tyssen commented 4 years ago

I've done a search on the entire project and there are no instances of exp:exp: anywhere. If there were, that would probably have caused the error on 3.0.6 too, wouldn't it?

croxton commented 4 years ago

Stash embeds templates are cached - have you tried clearing the cache? I'm struggling to see how Stash could change a tag in a template like that. Stash invokes EE's own parsing routines, it doesn't parse the tags itself. Perhaps there's some other error, like an unclosed tag pair or a hidden character, that is messing with the EE's tag-matching? Difficult to say. Perhaps you could try removing sections of code from the views/home template to identify exactly where the error occurs. Make sure to clear the cache after each test, or use replace="yes" on the embed.

tyssen commented 4 years ago

So this is what I've found out so far. Original embedded template looks like this:

{exp:channel:entries channel="home"}
{stash:embed name="layouts:global"}
{exp:stash:set name="st_content" type="snippet"}
    content
{/exp:stash:set}
{/exp:channel:entries}

That produces the error. This doesn't produce the error:

{stash:embed name="layouts:global"}
{exp:stash:set name="st_content" type="snippet"}
    content
{/exp:stash:set}

The embedded layouts:global template doesn't seem to be at fault because I've tested with it completely blank both with and without the channel entries tag and it's only when the channel entries tag wraps around the embedded template that the problem occurs.

The only reason the channel entries tag is wrapping the embed on this page (and some others) is to pass some data to embed variables.

croxton commented 4 years ago

I've not been able to reproduce this I'm afraid. I recreated your templates on a vanilla install of EE, and it seems to work as expected.

I have a hunch what might be the issue. The parsing of the {stash:embed..} tags is done using the template_fetch_template extension. It's possible that another add-on using this hook is not setup to use the result of the last call of the extension. Basically in the function triggered by the extension you need something like this at the top:

public function template_fetch_template($row) {    
        // get the latest version of $row
        if (isset(ee()->extensions->last_call) && ee()->extensions->last_call) {
            $row = ee()->extensions->last_call;
        } 
       // rest of function here

       // must return $row here
       return $row;
}

I would have a look at the other addons you have installed and see if disabling them (or adding the code above) helps.

tyssen commented 4 years ago

I've actually reworked all the templates now so the channel entries tag isn't wrapping the global embed and passing the variables in like this instead:

{stash:embed
  name="layouts:global"
  stash:_page_title="{exp:stash:get name='st_meta_title' process='end'}"
}

{exp:channel:entries}
{exp:stash:set name="st_meta_title"}{title}{/exp:stash:set}
{/exp:channel:entries}

Probably should've been doing it from the start, but it's interesting that it worked before but not now. It could be another extension but I think reworking the templates probably would've been the quicker job than trying to track it down.

Thanks for taking the time to investigate though. 👍