XF 2.2 Accessing error parameters in template


I want to modify the error template to display more info on some of my custom errors. How do I access the params shown in this dump from the template?
array:4 [▼
  "xf" => array:36 [▶]
  "errors" => array:1 [▶]
  "error" => Phrase {#282 ▼
    #language: Language {#232 ▶}
    #name: "my_error_name"
    #params: array:3 [▼
      "my_error_param" => 128
      "my_error_url" => "https://www.whateversomething.co.uk/"
      "my_error_otherstuff" => true
    #allowHtml: true
    #options: []
  "forJson" => true
I can access them in the error phrase as {my_error_param} etc but I want to use them in the template to do more complicated stuff something like the pseudo-code below rather than squish everything into the phrase, especially since the phrase editor tells me 'ideally markup should be made in templates, rather than phrases.'. I'm just not clear how I navigate through the dumped var above to get the pieces.
<xf:if this is a my_error_name error and my_error_otherstuff is true>
   obviously this is pseudo code but i want to access {my_error_param} and {my_error_url} and things and whatnot in here


Baby Community

Well-known member
It is inconvenient to play with xenforo templates. You will get big error when you play with these templates in future updates. Addons are made so we don't play with templates


XenForo moderator
Staff member
You call them in a template using $error.my_error_param and $error.my_error_url.

The main error var being a phrase is a bit odd though.


You call them in a template using $error.my_error_param and $error.my_error_url.
Right, so when I've tried that I get
public:error - Cannot use object of type XF\Phrase as array in /Users/kirsty/Documents/XenForo Dev/xen/internal_data/code_cache/templates/l1/s1/public/error.php:38
which suggests that you are right when you say

The main error var being a phrase is a bit odd though.

I just followed the way errors were being sent in XF\Service\Thread\Creator, that I am extending, which has, for example
$thread->error(\XF::phrase('please_select_valid_thread_type'), 'discussion_type');

How should I be sending the error instead?