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

Using tags made with addFunction(Smart) not usable when nested. #327

Open
dimitrihilverda opened this issue Oct 7, 2021 · 0 comments
Open

Comments

@dimitrihilverda
Copy link

I found this bug

When you create your own function with addFunction or addFunctionSmart and like to use the results in another fenom tag/function, i get errors

This is Fenom and PHP version and environment (server/fpm/cli etc) I am using

I use Fenom parser in MODx on php7.4

This is the function in my class

public function getHolderByVakgebied($vakgebied): ?string {
		if ($website_config_resource = $this->modx->getObject('modResource', $this->modx->getOption('website_config_id'))) {
			if (!empty($website_config_resource->getTvValue('vakgebied_' . $vakgebied))) {
				return $website_config_resource->getTvValue('vakgebied_' . $vakgebied);
			}

			if (!empty($website_config_resource->getTvValue('vakgebied_default'))) {
				return $website_config_resource->getTvValue('vakgebied_default');
			}
		}

		return 'No holder found for: ' . $vakgebied.' Config resource id: '. $this->modx->getOption('website_config_id');
	}

This is a plugin code snippet I use to add the tag

$fenom->addFunction("getHolderByVakgebied", [$modx->adwUbeeo, 'getHolderByVakgebied']);

Calling this as: {getHolderByVakgebied $_modx->resource.ubeeo_vakgebied} works fine. but using it like this:

{foreach json_decode(getHolderByVakgebied $_modx->resource.ubeeo_vakgebied, true) as $block index=$index}
does not work and gives errors, I also tryed to set it as a variable first like this:
{var $blocks = getHolderByVakgebied $_modx->resource.ubeeo_vakgebied}
same errors.
This function uses $this->modx->..., so I can not make it static...

The only way I got this to work on my tests is to allow php in tags and skip the whole addFuction part and call the function directly, but that is not so safe I think:
{foreach json_decode($modx->adwUbeeo->getHolderByVakgebied($_modx->resource.ubeeo_vakgebied), true) as $block index=$index}
but that works fine.

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

No branches or pull requests

1 participant