0

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'))
  &#123;
      include_once PATH_THIRD . 'stash/mod.stash.php';
  &#125;

  $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:

&#123;exp:channel:entries&#125;

Please correct the syntax in your template.

The template code is [code]{entry_id} {exp:channel:entries channel="clients" entry_id="18813" status="not closed" } {title} {/exp:channel:entries}[/code]

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})

I put together a quick function in my module called "test_stash" which DOES work.

    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;

}

So it seems like the issue is with parsing the tag in my EXTENSION. Is there anything about this which could be causing an issue?

The extension fires on channel_form_submit_entry_end.

Any help/advice appreciated. Thanks.

1

Quick 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.

| 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.