Extension, Module

Archived
Forum
(read-only)

Stash

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5, ExpressionEngine 6

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Stash Parse not parsing EE tags in an addon.

Support Request

Boiler Room Digital
Boiler Room Digital

Hello.

I’m writing an addon which can take an EE template, replace some variables and then *crucially* parse the EE tags in it and then email it.

I was hoping stash:parse might come to my rescue after a day of poking around various addons code and other options.

So here’s what I want to do:

echo "Template following process 1: $msg_body<br>";
  
  if ( ! 
class_exists('Stash'))
  
{
      
include_once PATH_THIRD 'stash/mod.stash.php';
  
}
  
  $stash 
= new Stash(TRUE); // instantiate with initialising

  
$params = array(
   
'process' => 'inline',
   
'parse_depth' => 5
  
);

  
$parsed_string $stash->parse($params$msg_body);
    
  echo 
"Template following process 2: $parsed_string<br>";

  return 
$parsed_string

This all seems to work - $msg_body is my template ready to parse. It contains a channel entries tag, which even when I make it as basic as possible, still gives the following error:

Error

The following tag has a syntax error
:

{exp:channel:entries}

Please correct the syntax in your template

The template code is

{entry_id}
{exp
:channel:entries
 channel
="clients" 
 
entry_id="18813" 
 
status="not closed"
}
 {title}
{
/exp:channel:entries} 

So unless I’ve missed something obvious, there isn’t a syntax error here.

It seems like this should work, especially as the parse example includes a channel entries tag (https://github.com/croxton/Stash/wiki/{exp:stash:parse})

Unless this only works when using the tag, rather than using Stash in my addon.

Any help/advice appreciated. Thanks.

Boiler Room Digital
# 1
Boiler Room Digital

Update - it works fine if I use that code in my module, just not in my extension. For example, the following module code works fine:

function test_stash(){
  
if ( ! class_exists('Stash'))
  
{
      
include_once PATH_THIRD 'stash/mod.stash.php';
  
}
  
  $msg_body 
'
{exp:channel:entries
 channel="clients" 
 entry_id="18813" 
 status="not closed"
}
 {title}
{/exp:channel:entries}'
;
  
  
$stash = new Stash(TRUE); // instantiate with initialising

  
$params = array(
   
'process' => 'inline',
   
'parse_depth' => 5
  
);

  
$parsed_string $stash->parse($params$msg_body);
  
  echo 
$parsed_string;

 

it’s only when I run the same code in an extension that I get an issue. It says there’s a syntax error in the tag, whatever tag I’m using.

Boiler Room Digital
# 2
Boiler Room Digital

Another update - having looked at what causes this error, I found that if I call

ee()->TMPL->fetch_addons(); 

in my extension before I call stash->parse, it works fine without an issue. Hope this helps someone.

 

Mark Croxton
# 3
Developer
Mark Croxton

Yes that is correct - this is how I do it in Stash’s extension: https://github.com/croxton/Stash/blob/master/system/user/addons/stash/ext.stash.php#L266-L269