XF 2.0 XF:Widget Class pulled from select menu

Russ

Well-known member
Is there some way of making a style property (select menu) control which widget is loaded?

This obviously doesn't work, but something along these lines
Code:
<xf:widget class="XF:{{ property('customWidget') }}" />

custom widget values being:

Birthdays=Birthdays
FindMember=FindMember
ForumStatistics=Forum Statistics

and so on...
 
For reasons I'm not currently sure of, no, that won't work.

This will though:
Code:
<xf:widget class="XF\Widget\\{{ property('customWidget') }}" />
That's the full class name, note the double \\ is important otherwise it will attempt to escape the first { character.
 
Lastly... related to this somewhat. I've tried multiple things so just coming on here :).

Using macros, have something along this up top in different spots:

Code:
<xf:macro name="customwidget" arg-block="1" />
Code:
<xf:macro name="customwidget" arg-block="2" />
Code:
<xf:macro name="customwidget" arg-block="3" />

Then below...
Code:
<xf:macro name="customwidget" arg-block="{$block}">
    <xf:set var="$mywidget" value="{{ property('customProperty{$block}') }}" />

    <xf:if is="{$mywidget} == 'option1'">111
    <xf:elseif is="{$mywidget} == 'option2'" />222
    <xf:elseif is="{$mywidget} == 'option3'" />333
    </xf:if>

</xf:macro>

customProperty# is 3 different dropdowns, each with the same options, option1/2/3.

Is there a way of passing the # via the arg-block, to the variable?

This works:

Code:
<xf:set var="$mywidget" value="{{ property('customProperty3') }}" />
but I want that 3 passed down through the macro. Hope that's not to terribly confusing, thanks guys.
 
That error is a bug which I've fixed, but there are several places in the template compiler code which assume the widget key/class is a literal string, so that's not really something that I'm prepared to change at this point. To do what you asked in the OP, you'd need to if/elseif based on the property name (which is frankly a bit safer in terms of if an invalid value ends up in the property).

In terms of the last question, if I'm understanding correctly, it's just:
Code:
<xf:set var="$mywidget" value="{{ property('customProperty' . $block) }}" />
 
Hopefully the last question regarding this...

Can you somehow do the same approach with this:

Code:
<xf:set var="$mywidget" value="{{ property('customProperty' . $block) }}" />

To a template include?

Code:
<xf:template="'customProperty . $block" />

Where the template names are customProperty1, customProperty2, customProperty3
 
Back
Top Bottom