XF 2.3 Can a .less template use forum variables?

Wildcat Media

Well-known member
Licensed customer
I'm writing an add-on and am using settings in an admin option to set a couple of style variables. I want to use those in a .less template.

Is it possible to do something like this?

CSS:
.my-style {
    width: // my option from admin here //;
}

The only problem I see is that in templates, the { } brackets in CSS/LESS would probably conflict with trying to insert a variable in a template which also uses brackets (like {$xf.options.myOptionHere} which is what I would do in a regular template).

Or do I need to add something in Style Properties instead, and then try to work those into my template mods instead?
 
Actually @Jeremy P I do have a question regarding the style properties.

I've added a new settings group under Style Properties. Is there a way to specify default values? I wasn't able to find any documentation for the "Value formatting parameters"...unless I'm just not searching for it properly.

1785543858924.webp
 
I'm writing an add-on and am using settings in an admin option to set a couple of style variables. I want to use those in a .less template.

Is it possible to do something like this?

CSS:
.my-style {
    width: // my option from admin here //;
}

The only problem I see is that in templates, the { } brackets in CSS/LESS would probably conflict with trying to insert a variable in a template which also uses brackets (like {$xf.options.myOptionHere} which is what I would do in a regular template).

Or do I need to add something in Style Properties instead, and then try to work those into my template mods instead?
Doing it without a style property would require you to rebuild styles on option save. You'd need to use XF\Option\Style::triggerStyleUpdate as your validation class/method.

The only time you should do this instead of actually using a style property would be if the setting also needs to control how you transform files, f.ex. attachment thumbnail dimensions.
 
Back
Top Bottom