How to conditionally add css class in view in web2py?

Tags: css,web2py

Problem :

In a web2py view, is there a concise way to add a css class to an html tag based on a conditional? I'm thinking something like this in pseudocode:

<div class="details {{if product.inventory == 0 then 'highlight'}}">...</div>

if product.inventory == 0 then the view will generate the following html:

<div class="details highlight">


<div class="details">

I know I can use a plain old if block in the view but I'm looking for a concise way to do this. Alternatively is there a better way to approach this?

Solution :

You've almost got it:

<div class="details{{=' highlight' if product.inventory == 0 else ''}}">

    CSS Howto..

    How do people make sections in HTML pages? [closed]

    how to vertically align this div?

    How to move Woocommerce Description tab below review tab

    Angular 2: How to change an element’s CSS class onclick and to remove all others (Plnkr)

    How to check the CSS hyphens in effect using Chrome developer tools?

    How to vertically center inline elements in CSS

    Slideshow by changing background-image CSS attribute using JQuery in Drupal 7

    How does this site hide the iframe scrollbar?

    How to reset css in middle of html document?

    Show unordered list's bullet points when display:table

    How to set a tooltip width dynamically?

    How to stop css class on textbox

    How to set dynamic value in css? [closed]

    How can clients without Ruby view web pages using SASS?

    How do I center bootstrap's carousel? Not the images, the carousel itself

    how to have spacing html/css

    How to fit the content of the site in any resolution CSS

    How do I remove column padding to have full-width inputs in Bootstrap 3?

    How to make flash movie to scale proportunatly to div width?

    How do i prevent my CSS affecting external plugins?

    How to make circle by using HTML CSS only?

    How to persist local CSS change to server record?

    How to use numbers from a js file in the css sheet?

    How to turn this menu into a MultiLevel one?

    How to use css transform-origin to show a circle of playing cards (rectangles)?

    How to change an input button with pure css button (no images)? [duplicate]

    How to apply different styles based on the number oif col in a table

    How to minified all js and css files using gruntfile.js in sails.js

    how can i change the style of scroll bar

    How can I use an alert or form input to allow a user to set a value of a CSS parameter [closed]