Skip to content

Conversation

@dragomano
Copy link
Contributor

@dragomano dragomano commented Nov 2, 2025

Adds support for callable strings (e.g., Class::method#) in the loadSubTemplate method, allowing both static methods and instance method calls with object caching. Adds the same support for the callback option in Admin.template.php

Example with callback functions:

<?php

namespace SMF;

class SomeClass
{
	public static function getConfigVars(): array
	{
		return [
			['callback', 'legacy_callback_name'], // looking for `template_callback_legacy_callback_name` function
			['callback', __CLASS__ . '::test#'], // looking for `test` method in the current class
			['callback', TestClass::class . '::test#'], // looking for `test` method in other class
			['callback', TestClass::class . '::test2'], // looking for `test2` static method in other class
		];
	}

	public function test(): void
	{
		echo __METHOD__;
	}
}

class TestClass
{
	public function test(): void
	{
		echo __METHOD__;
	}

	public static function test2(): void
	{
		echo __METHOD__;
	}
}

Example with subaction:

Utils::$context['sub_template'] = 'show_settings'; // current (legacy)
Utils::$context['sub_template'] = TestClass::class . '::test#'; // new

Example with layers:

Utils::$context['template_layers'][] = TestClass::class . '::test#';
<?php

namespace SMF;

class TestClass
{
	public function testAbove(): void
	{
		echo 'above';
	}

	public function testBelow(): void
	{
		echo 'below';
	}
}

Signed-off-by: Bugo <229402+dragomano@users.noreply.github.com>
Signed-off-by: Bugo <229402+dragomano@users.noreply.github.com>
@dragomano dragomano changed the title Extend template system with callable support [3.0] Extend template system with callable support Nov 2, 2025
Signed-off-by: Bugo <229402+dragomano@users.noreply.github.com>
Copy link
Contributor

@live627 live627 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should similar code in the profile area also be updated?

Signed-off-by: Bugo <229402+dragomano@users.noreply.github.com>
@Sesquipedalian
Copy link
Member

This is a cool idea, but we might end up making profound changes to the theme system in 3.0. For that reason, I recommend that you don't invest much effort into theme-related code until that has been settled.

Signed-off-by: Bugo <229402+dragomano@users.noreply.github.com>
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.

3 participants