conditional formatting based on deck

C's Avatar

C

29 Dec, 2016 10:35 AM

Hi, is there any way that I can change the background colour of a card only when it forms part of a stated deck.
That is, using just one card type, when a card of that card type is in Deck A its background is green, and if I move it to Deck B its background will be white.
Many thanks

  1. 1 Posted by Soren Bjornstad on 29 Dec, 2016 04:02 PM

    Soren Bjornstad's Avatar

    Hi C,

    No, it's not possible to condition part of a template based on what deck it's in. You can display the deck name on the card with {{Deck}}, but that won't help with changing the background color.

    If you only have a couple of decks, you could maybe make fields called "Deck1" or whatever and use conditional replacement to change the background color. But then if you moved a card between decks you'd have to remember to change the contents of those fields as well.

  2. 2 Posted by C on 29 Dec, 2016 05:21 PM

    C's Avatar

    Thanks for the reply, I'll use {{Deck}} as you suggest.

  3. 3 Posted by Glutanimate on 29 Dec, 2016 06:17 PM

    Glutanimate's Avatar

    One thing that's hacky, but could work for you still, is to use the deck name as a CSS class.

    For instance this setup...

    Styling:

    .deck1 {
        background-color: yellow;
    }
    
    .deck2 {
        background-color: blue;
    }
    

    Template:

    <div class="{{Deck}}">
        {{Back}}
    </div>
    

    ...should color the card yellow when it's in deck1 and blue when it's in deck2.

    One of the limitations you have to keep in mind with this approach is that any type of CSS-invalid characters might end up messing up your formatting. See here for a list of valid CSS class name characters.

    The same approach works for tags and any type of field, by the way.

  4. 4 Posted by Soren Bjornstad on 29 Dec, 2016 10:49 PM

    Soren Bjornstad's Avatar

    While definitely hacky, that's brilliant -- thanks for the contribution!

  5. 5 Posted by Ankitest on 02 May, 2017 04:04 AM

    Ankitest's Avatar

    It's better to use {{Subdeck}} because:

    .Geo::Seas { ... }
    

    does not work as class name.

    Also it is the problem when deck name contains a space: Oceans and seas

  6. 6 Posted by Ankitest on 02 May, 2017 08:59 AM

    Ankitest's Avatar

    .

  7. 7 Posted by cjastles on 30 Nov, 2018 09:37 AM

    cjastles's Avatar

    @Dmitry Is this add-on no longer available? It would be perfect for me.

  8. 8 Posted by sabayon11 on 22 Dec, 2018 01:34 PM

    sabayon11's Avatar

    Has anyone have a copy of this 1523985889 add-on "if tag ..."?

Comments are closed, but you can start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac