XF 2.0 What is the correct way to include custom js in style properties?

CyberAP

Well-known member
Let's say I have a custom style property group and want to add some js color processing on the fly, what would be the correct way to include my js there?
 
This is likely to be something that's more under the scope of an add-on. You could likely do it with a custom template type style property. (There may be some other hacks, probably involving the description, but I wouldn't necessarily recommend those.)
 
This is likely to be something that's more under the scope of an add-on. You could likely do it with a custom template type style property. (There may be some other hacks, probably involving the description, but I wouldn't necessarily recommend those.)
Thank you, I have looked up XF\Entity\StyleProperty.php and it seems like it's not possible since _preSave() is a protected function and only allows 'Value' and 'CSS' types, ignoring others and always returning an error. Or this can be somehow ignored?
 
Sorry, my bad, it already supports template inclusion for value type. Though it is not clear how do I reference a template here:

1506627398881.webp
 
Oh, I neglected a point.

Because value parameters can include other bits of info, the parameters need to be in key => value pairs, so you'd enter:
Code:
template=public:my_template
See the messageUserElements property for an example.
 
Oh, I neglected a point.

Because value parameters can include other bits of info, the parameters need to be in key => value pairs, so you'd enter:
Code:
template=public:my_template
See the messageUserElements property for an example.
Thank you, there's another caveat to that. There must be 2 elements there: template and type. If the first one is obvious, the second one can only be guessed by looking into the source code, and I found out that there are only 2 types supported there: array and scalar. So my final code looked like this:
Code:
template=public:my_template
type=scalar
This is very unclear for the first time, maybe it'd be worth adding some info in the error message?
 
Does anyone know how to get to the screen which @CyberAP posted above, where you can set up a custom property in a style? The screen that looks like this:

1506627398881.png


I am trying to add a custom property to a style, but do not know how to get to the screen above which allows you to define a new custom property. I am using Xenforo 2.0.
 
Last edited:
I've just realized that in order to add a new custom property, you have to be in debug mode (it states that here).

As a workaround, instead of switching on debug mode, I just exported the Xenforo forum style (from Appearance > Styles > ... > Export), and edited the document to add a new custom property, by adding the following code (which adds a custom property to control color):
XML:
<property property_name="nameOfCustomProperty" group_name="palette" title="Short description of custom property" description="Long description of custom property" property_type="value" value_type="color" depends_on="" value_group="" display_order="50" addon_id="">
      <value>"rgb(0, 0, 0)"</value>
</property>


This adds a custom property named nameOfCustomProperty, which can be referenced in any CSS stylesheet as the variable @xf-nameOfCustomProperty.

I then just re-imported the edited style back into the Xenforo.
 
Back
Top Bottom