Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django applying a style class based on a conditional

I am displaying a list of images. If the user has uploaded an image, I want to keep its opacity 0.5 and in the list of images, the images uploaded by others should have full opacity. I have done it as follows, is there a better way to do it??

{% if request.user == obj.shared_by %}        <div class="item-image" style="opacity:0.5;filter:alpha(opacity=50);">            {% else  %}           <div class="item-image">            {% endif %}         ......Some code here....        </div> 

Thanks!

like image 338
whatf Avatar asked Jan 19 '13 09:01

whatf


1 Answers

I normally go for:

<div class="item-image{% if foo %} own-image{% endif %}">...</div> 

but switching out the entire div tag may be more readable.

Either way I'd do the styling with another class, not with inline css.

like image 85
second Avatar answered Oct 12 '22 14:10

second