1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Implemented {xen:link string to array for data

Discussion in 'Closed Suggestions' started by Robbo, Feb 7, 2012.

  1. Robbo

    Robbo 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
    Code:
    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);
    	}
    	else
    	{
    		$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.
     
  2. Mike

    Mike XenForo Developer Staff Member

    {xen:link threads, {xen:array 'thread_id=43'}}

    That should work (haven't double checked).
     
  3. Robbo

    Robbo Well-Known Member

    Oh, never noticed that. Thanks heaps! Thought there must be a way somehow.
     

Share This Page