Implemented {xen:link string to array for data


Well-known member
I would like to be able to do {xen:link route, 'test=1;test=2'}. Basically make the array in the template so for example I could link to a thread without any PHP with {xen:link thread, 'thread_id=43'}.

I messed around with the compiler and was able to get it working with some hacky looking code.

XenForo_Template_Compiler_Function_Link Line ~31
if (isset($arguments[0]))
	$dataRef = array_shift($arguments);
	if (isset($dataRef[0]))
		$args = explode(';', $dataRef[0]);
		foreach ($args as &$arg)
			$arg = array($arg);
		$data = $compiler->getNamedParamsAsPhpCode($compiler->parseNamedArguments($args), $options);
		$data = $compiler->compileAndCombineSegments($dataRef, array_merge($options, array('varEscape' => false)));
Hacky but my quick tests worked. Could you do something a little less hacky? This is something I thought would be done in some form by now.

Would be nice if we could extend the compiler more as well, seems very limited how it is at the moment unless I am missing something.


XenForo developer
Staff member
{xen:link threads, {xen:array 'thread_id=43'}}

That should work (haven't double checked).