Welcome Guest, Not a member yet? Register   Sign In
run the plugin at the end of the parser
#1

Hi All.
I have a suggestion
Since the plugin is executed before the loop over the data variable, we cannot use variables in the plugin
the following script will cause a parse error.
{+ foo bar={bash} +}

To work around this parsePlugins is executed after the loop over the data variable



PHP Code:
    /**
    * Parse a template
    *
    * Parses pseudo-variables contained in the specified template,
    * replacing them with the data in the second param
    *
    * @param array $options Future options
    */
    protected function parse(string $template, array $data = [], ?array $options null): string
    
{
        if ($template === '') {
            return '';
        }

        // Remove any possible PHP tags since we don't support it
        // and parseConditionals needs it clean anyway...
        $template str_replace(['<?''?>'], ['&lt;?''?&gt;'], $template);

        // temporarily replace the plugin tag so it doesn't trigger an error during the loop
        $template str_replace(['{+''+}'], ['#$''$#'], $template);

        $template $this->parseComments($template);
        $template $this->extractNoparse($template);

        // Replace any conditional code here so we don't have to parse as much
        $template $this->parseConditionals($template);

        
        
// loop over the data variables, replacing
        // the content as we go.
        foreach ($data as $key => $val) {
            $escape true;

            if (is_array($val)) {
                $escape  false;
                $replace $this->parsePair($key$val$template);
            } else {
                $replace $this->parseSingle($key, (string) $val);
            }

            foreach ($replace as $pattern => $content) {
                $template $this->replaceSingle($pattern$content$template$escape);
            }
        }

        // return plugin tag before running parsePlugins
        $template str_replace(['#$''$#'], ['{+''+}'], $template);
        // Handle any plugins before normal data, so that
        // it can potentially modify any template between its tags.
        $template $this->parsePlugins($template);
        
        
return $this->insertNoparse($template);
    
Reply
#2

I didn't have this issue, but maybe better option would be to made two types of plugins, one that are parsed as they are now, and second that works as you suggested. Distinction between them could be made as folder category or plugin naming convention
Thread about my project that is using CodeIgniter:
Reply
#3

(02-03-2022, 09:57 AM)Acuru Wrote: I didn't have this issue, but maybe better option would be to made two types of plugins, one that are parsed as they are now, and second that works as you suggested. Distinction between them could be made as folder category or plugin naming convention
My suggestion is based on this thread

https://forum.codeigniter.com/thread-799...ht=plugins
Reply




Theme © iAndrew 2016 - Forum software by © MyBB