custom-cards / decluttering-card

🧹 Declutter your lovelace configuration with the help of this card
MIT License
372 stars 30 forks source link

Inherit another template or optional variables? #68

Open jeremywillans opened 1 year ago

jeremywillans commented 1 year ago

Is your feature request related to a problem? Please describe. I have several fairly duplicated templates which have something minor as a difference, for example an extra service-data parameter or one with an extra option.

Describe the solution you'd like Is there a way to either inherit config from another template, or exclude parts of the template based on if you have specified the particular variable?

Describe alternatives you've considered Multiple templates

ildar170975 commented 1 year ago

Similar functionality may be achieved by "cascading" templates & using yaml anchors:

template_1:
  default: &ref_default
    - var_1: ...
    - var_2: ...
    - ...
  card:
    ...
...
template_2:
  default: *ref_default
  card:
    ...
    - &ref_calling_template_1
      type:custom:decluttering-card
      template: template_1
      variables:
        - var_1: '[[var_1]]'
        - var_2: '[[var_2]]'
    ...
...
template_3:
  default:
    ... new default values
  card:
    ... another functionality
    - *ref_calling_template_1
    ... another functionality
jack3308 commented 10 months ago

Just to confirm, this approach would only work when using the yaml development method and not the UI, correct?

ildar170975 commented 10 months ago

yaml-anchors are supported in yaml mode only.