Skip to main content
13-Aquamarine
August 3, 2020
Question

Update Custom CSS through a service

  • August 3, 2020
  • 2 replies
  • 2951 views

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?

2 replies

16-Pearl
August 3, 2020

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

13-Aquamarine
August 4, 2020
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
1-Visitor
November 8, 2021

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>';