Variables in CSS template

MOZ

Well-known member
Working on an addon, the need arised to generate a CSS from a table in the DB much like how the smilie sprites are generated. I was looking at how to use variables inside css templates, but I searched but got no result.

However what I realised was that in XenForo_CssOutput::renderCss, there were a handful of variables being passed when CSS is rendered (They aren't using MVC for this, to speed things up). Now if I understand correctly it is impossible to extend this method?

However out of the available variables, one is $xenOptions. So we can store out data in $xenOptions as a pseudo option (Option that is text type with an empty template defined as option format) , meaning store data in pseudo option, define fetch options value and use in css template. Enjoy!

Now, for the big question, this is one way of doing it, second way of achieving the same is a little hackish. This is to generate the complete CSS and store it in styles folder upon editing/deleting actions (On the data in the DB) and then use temple_hook/post_render to add the link href to the css.

Which method is better in your opinion?
 
Update: no need for serialization/unserialization, just have Option as Array type
 
Top Bottom