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

Feature/twig hooks filters #258

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

Conversation

slawkens
Copy link
Owner

This commit introduces new type of hooks: filters.

The usage is similar to WordPress filters: https://developer.wordpress.org/plugins/hooks/filters/

Example 1:

Hook into twig->display & $twig->render

Plugin.json:

"hooks": {
	"Twig Display": {
		"type": "FILTER_TWIG_DISPLAY",
		"file": "plugins/example/twig-display.php"
	}
},

plugins/example/twig-display.php

<?php

// if the template is characters.html.twig, replace the town visible for user
if ($args['viewName'] == 'characters.html.twig') {
	$args['town'] = 'My Custom City';
}
return $args;

Example 2

Remove Powered by MyAAC

Plugin.json

"hooks": {
	"Twig Display": {
		"type": "FILTER_THEME_FOOTER",
		"file": "plugins/example/remove-footer.php"
	}
},

plugins/example/remove-footer.php

<?php

/**
 * @var array $args
 */

$elementsToRemove = [];
foreach ($args as $id => &$footerPart) {
	if (str_contains($footerPart, 'Powered by')) {
		$elementsToRemove[] = $id;
	}
}

foreach ($elementsToRemove as $id) {
	unset($args[$id]);
}

return $args;

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.

1 participant