Skip to content

Conversation

@oiseauroch
Copy link
Contributor

@oiseauroch oiseauroch commented Oct 14, 2025

Current behavior

Creating a new component with body and then as a closing {{end elem="mycustomelement" }} element require to add code in the core of yeswiki to add **customelement** into end.php` file.

Expected behavior

I would like to be ablo to add a custom element without modifying something that could be removed by update.

Proposal

We could had a default case for end element that look for a end() fonction in the extra YesWiki action like this :

            default:
                echo $this->services->get(Performer::class)->run($elem, 'action', [], true);
                break;
  • proposition validated
  • implementation tested

@oiseauroch
Copy link
Contributor Author

a new custom action can now be written as :

<?php

use YesWiki\Core\YesWikiAction;

class ColorAction extends YesWikiAction
{

    public function run()
    {
        $class = $this->arguments['class'] ?? '';
        $color = $this->arguments['color'] ?? (empty($class) ? 'var(--neutral-color)': 'var(--' . $class . ')' );

        if ($this->check_end_elem('color')) {
            return "<span class='color-elem' style='color: $color;'>";
        } else {
            return $this->generate_error_msg('color');
        }

    }

    public function end(): string {
        return '</span>';
    }
}

and use like this :

{{color color="#FFFFFF"}}
my colored text
{{end elem="color"}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants