Skip to main content
13-Aquamarine
Aug 3, 2020 2:20 PM UTC
Question

Update Custom CSS through a service

I need my Custom CSS for a given mashup to be dynamic.  In order to do that I need to be able to update my mashup Custom CSS through a service.  Is there a way to do this?

4 replies

16-Pearl
Aug 3, 2020 2:50 PM UTC

CustomClass property is bindable. So you can dynamically change class name using the string output of a service. 

Translate
13-Aquamarine
Aug 4, 2020 5:23 PM UTC
I'm looking for something like the following but I don't know what output I
should use for the script or how I would bind it to the given widget.

https://community.ptc.com/t5/Vuforia-Studio/Edit-CSS-Styles-with-JavaScript/m-p/549899
Translate
1-Visitor
Nov 8, 2021 3:40 PM UTC

One way you can do this is to use a legacy value display and set its formatting to unsanitized HTML. Just be very careful to properly secure the dynamic parts of your stylesheet so you don't create security issues. Also keep in mind that invalidating the stylesheets is slow so you shouldn't do it very often.

 

With those points in mind, you can write a service that outputs a style tag that then gets added to the page, e.g.:

const result = '<style> .MyClass { color: ' + myColor + '; } </style>';

 

Translate