Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

namespace-based plugins using autoload() #730

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

SlowFox71
Copy link

No description provided.

@wisskid wisskid added the waiting Waiting for answer label Jul 16, 2022
@wisskid
Copy link
Contributor

wisskid commented Jul 16, 2022

This looks promising. Could you provide an explanation of what you are trying to accomplish?

@SlowFox71
Copy link
Author

Personally, main motivation was the use of namespace-based constants in plugins, i.e. being able to write things like


namespace SmartyPlugins;

class Link {

        const DECORATION_NONE = 'none';
        const DECORATION_BUTTON = 'button';
        const DECORATION_ICON = 'icon';

        public static function block($params, $content, $smartyInternalTemplate, &$repeat) {
           [...do the magic...]
        }
}

and being able to use this in my template as

{link page=\Page\SomePage::class decoration=\SmartyPlugins\Link::DECORATION_BUTTON}Text{/link}

Other than with magic strings I can (via AST) automatically check templates for correct/existing constants which (for me) was a huge improvement for the quality of user-modified templates.

Another benefit is auto-loading via PHP-autoloader (instead of doubling this within Smarty). This allows me to intercept plugin-loading at the same point where I do it for all the other classes.

Possible future benefit could be implementation of block/function within the same class, e.g.

{link page=\Page\PageProvidingOwnLinkText::class} 
{link page=\Page\PageProvidingOwnLinkText::class}Customized link text{/link}

However, this would require modifications in the parser.

For a distant future it could be a step to the general usage of namespaces by Smarty. Internal plugins could use this logic (and then easily being overloaded via Autoloader if necessary).

@wisskid wisskid removed the waiting Waiting for answer label Sep 14, 2023
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.

None yet

3 participants