voidlabs / mosaico

Mosaico - Responsive Email Template Editor
https://mosaico.io
GNU General Public License v3.0
1.68k stars 502 forks source link

default value for select widget #701

Closed InfGame closed 8 months ago

InfGame commented 8 months ago

Heya! I have a select widget for a color theme that i use in many templates of mine:

colorStyle {
  label: Color;
  widget: select;
  options: Red=Rot|Green=Grün|Blue=Taubenblau|DarkBlue=Dunkelblau|Oliv|Neutral;
}

Tho i would like a different theme to be the default on different templates.

Is there any way to define a default value on a select widget?

The selections reffere back to a list of hexcodes that are used in an element's css that uses the theme like this:

-ko-background-color: @[colorStyle == 'Green' ? '#ebf1eb' : colorStyle == 'Blue' ? '#e9f0f5' : colorStyle == 'DarkBlue' ? '#e5ecf0' : colorStyle == 'Oliv' ? '#edeeec' : colorStyle == 'Neutral' ? '#f3eeea' : '#f5e6e9']

bago commented 8 months ago

Defaults are not a widget thing, but a "variable" thing. Most times the default is automatically read from the HTML/CSS value, but in your case you use an expression so Mosaico is not able to guess it and you have to make it explicit in the block definition, e.g:

myBlock {
  properties: **colorStyle=Blue** otherProps anotherOne;
}