passing a context object to css

39 views
Skip to first unread message

gazza

unread,
Oct 20, 2014, 6:31:00 PM10/20/14
to pylons-...@googlegroups.com
Hello,

Normally I would pass my context object to a template. However I would like to
pass this to a css class.

 i.e c.color="red"

Is this possible? or do I have to add a style statement in html on the template.

Thanks,
Gary C

Laurent DAVERIO

unread,
Oct 20, 2014, 6:45:55 PM10/20/14
to pylons-...@googlegroups.com
Hello,

I would probably prefer to keep all my CSS files as purely static files,
for performance reasons (actually, I would create Sass files, and have
Fanstatic automatically compile and minify them for me, but that's
another story)

Mako can be used for creating CSS templates, but then these CSS files
won't have the same path as the static ones (they will live with your
HTML templates), so you'll need to remember which is which when you
include them in your HTML code. That's probably the way you must go. In
that case, I would keep the "dynamic CSS" to a minimum, i.e. a single,
short file overloading a static CSS file.

Hope this helps,

Laurent.
> --
> You received this message because you are subscribed to the Google
> Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pylons-discus...@googlegroups.com
> <mailto:pylons-discus...@googlegroups.com>.
> To post to this group, send email to pylons-...@googlegroups.com
> <mailto:pylons-...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/pylons-discuss.
> For more options, visit https://groups.google.com/d/optout.

Torsten Irländer

unread,
Oct 21, 2014, 2:52:11 AM10/21/14
to pylons-...@googlegroups.com
Hi,

+1 for mako.
I also use mako to generate the CSS files if I want to add some dynamic content. This works pretty well so far here.

gazza

unread,
Oct 21, 2014, 10:30:13 AM10/21/14
to pylons-...@googlegroups.com
Thanks. Not sure how to use mako to genetate css files. Yes I need to have some dynamic content in the css. Could you be so kind
and forward a link or an example on how to do this with mako?

Jonathan Vanasco

unread,
Oct 21, 2014, 12:06:29 PM10/21/14
to pylons-...@googlegroups.com
You have 3 options:

1. Generate the CSS in your main template (in a style section)
2. Generate the CSS as a dynamic file 
3. Use a static CSS file, and generate CSS overrides in the main template (in a style section)

I prefer option 3.  

gazza

unread,
Oct 21, 2014, 3:31:45 PM10/21/14
to pylons-...@googlegroups.com
Yes point 3 seems the best option. Simply override the css and stick the c.color in the style section.
Reply all
Reply to author
Forward
0 new messages