XF 2.2 Passing attributes to a class widget?

kirsty

Member
I can define a widget in a template using

Code:
<xf:widget class="Blah\Widget\TestWidget" />

but although I'm told this...
  • You can also provide widget-specific options as attributes when the class attribute is used.

I can't figure out the right syntax to provide the options.

I've tried various variations on passing in paramName='paramValue' in the xf:widget tag (e.g. params="['abc']" is how they work in an xf:callback) but I haven't hit on anything that turns up when I getContextParams() in the widget's render method. Maybe the context params the wrong place to be looking? But I've dumped all the vars and can't see my params anywhere.

(The same question was asked here but it didn't get answered.)
 
I kept digging and eventually got it sussed. You need to pass in the attribute with a context- prefix and then you can get at it in the render method without the prefix.

E.g. in the template

Code:
<xf:widget class="Blah\Widget\TestWidget" context-stuff="my stuff in here"/>

and in the widget's render() method

Code:
$contextParams = $this->getContextParams();
$mystuff = $contextParams['stuff'];
 
Back
Top Bottom