Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
To Include or Not to Include CSS in Display Templates
What's the best practice for using custom CSS in Display templates? Is it a good idea? Bad idea?
There are certain instances where I can't see how this is avoidable (setting the background of a div to the image in the structure), but what is the best way?
I like the idea that the display template can basically be self-contained, with it's own CSS, but then does that cause issues elsewhere?
Thanks!
There are certain instances where I can't see how this is avoidable (setting the background of a div to the image in the structure), but what is the best way?
I like the idea that the display template can basically be self-contained, with it's own CSS, but then does that cause issues elsewhere?
Thanks!
John CressmanWhat's the best practice for using custom CSS in Display templates? Is it a good idea? Bad idea?
There are certain instances where I can't see how this is avoidable (setting the background of a div to the image in the structure), but what is the best way?
I like the idea that the display template can basically be self-contained, with it's own CSS, but then does that cause issues elsewhere?
I tend to go with my default answer: "It depends (TM)"
If it's positional (e.g. columns or embedding an image in text, floating) I lean towards embedded CSS. If it's decorating with a specific color (that might be changed with the next CI/theme update, I lean towards not doing so. If the image that you mention is part of the content (e.g. an uploaded image): leaning towards yes. If it's a design element (e.g. pretty border): No.
To summarize: It depends. ;)
After all, you'll have to evaluate if the extra price for "doing it properly" is worth it - e.g. do you want to redeploy your theme? Do you even have control over it? Is this a one-off situation or a general strategy? I tend to solve "one-offs" on the spot, knowing that they can easily creep up to "one-more-offs" and "only-one-more-off-please". When I realize that there's now plenty of them, then it's time to remodel and generalize. But I tend to not build a pretty and future-proof solution that is so unusual that nobody will ever be aware of either situation (neither the shortcut, nor the brilliantly architected version)
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™