Table of Contents

Class FacetOptionViewModelExtensions

Namespace
Dynamicweb.Ecommerce.ProductCatalog
Assembly
Dynamicweb.Ecommerce.dll

Extension methods for FacetOptionViewModel.

public static class FacetOptionViewModelExtensions
Inheritance
FacetOptionViewModelExtensions
Inherited Members

Methods

TryGetColor(FacetOptionViewModel, out ColorViewModel?)

Tries to resolve a ColorViewModel from a facet option whose value represents a colour.

public static bool TryGetColor(this FacetOptionViewModel facetOption, out ColorViewModel? color)

Parameters

facetOption FacetOptionViewModel

The facet option to examine.

color ColorViewModel

When this method returns true, contains a ColorViewModel with the resolved hex colour; otherwise null.

Returns

bool

true in either of these cases:

  • Value is a CSS hex colour string of length 7 ("#RRGGBB") or 4 ("#RGB").
  • Value matches a variant option that has a non-empty colour defined.

Otherwise false.

Remarks

Use this in Razor templates to render a colour swatch instead of a plain text label:

@if (option.TryGetColor(out var color))
{
    <span style="background:@color.Hex" class="color-swatch"></span>
}
else
{
    <span>@option.Label</span>
}

See Also

To top