CodeIgniter Forums
Parser Plugins - Open & Closing Tag Usage - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Parser Plugins - Open & Closing Tag Usage (/showthread.php?tid=87407)



Parser Plugins - Open & Closing Tag Usage - ltarrant - 04-17-2023

Hi,
I am trying to create some custom parser plugins within a module I am working on.
I have single tag plugins with or without parameters functioning fine.
However, when I try to use opening and closing plugin tags the closing tags line is rendered in the output. I am also unsure how to access the content within the tags from withing my plugin function.
The documentation for parser plugins is fairly sparce. Any examples of an open and closing tag plugin functions would be much appreciated.


RE: Parser Plugins - Open & Closing Tag Usage - JustJohnQ - 04-17-2023

It would help if you show your code


RE: Parser Plugins - Open & Closing Tag Usage - ltarrant - 04-20-2023

I am loading plugins using my modules Config\Registrar.php:

Code:
class Registrar
{
    public static function View(): array
    {
        return [
            'plugins' => [
                'include' => '\Modules\CMS\Libraries\ParserPlugins::include',
                'test' => '\Modules\CMS\Libraries\ParserPlugins::test',
            ],
        ];
    }
}
My ParserPlugins class contains the following:

Code:
class ParserPlugins
{
    public static function include(array $params = [])
    {
        $parser = \Config\Services::parser();
        return $parser->render(...$params);
    }

    public static function test(array $params = [])
    {       
        return 'Test';
    }
}

I try to use opening and closing plugin tags like so:

Code:
{+ test +} inner content {+ /test +}

However, the only params I can access are those I add to the opening tag. I am unsure how to access the content between the tags.

The closing tag is also still be rendered on the page as
Code:
{+ /test +}
.