📢 Use this project, contribute to it or open issues to help evolve it using Store Discussion.
The Product Highlights app provides blocks to display highlight badges on products according to the collection or promotion they are linked to.
In the image above, the product has a Top Seller
highlight.
In your theme's manifest.json
file, add the Product Highlights app as a dependency:
"dependencies": {
+ "vtex.product-highlights": "2.x"
}
Now, you can use all the blocks exported by the product-highlights
app. Check out the full list below:
Block name | Description |
---|---|
product-highlights |
Parent block responsible for defining, according to its children blocks (product-highlight-text and product-highlight-wrapper ) and props, how the Product Highlights component will be displayed. |
product-highlight-text |
Renders a span HTML tag with the hightlight name. It also provides data attributes and CSS handles for style customizations. |
product-highlight-wrapper |
If you need to render other blocks along side with the highlight name, you may use this block. It renders a div HTML tag and its children blocks (if any). |
According to your desire, copy one of the examples stated below and paste it in your theme's desired template, making the necessary changes. Remember to add the product-highlights
block to the template's block list if needed.
- Simple example:
{
"[email protected]:product-highlights": {
"children": ["product-highlight-text"]
},
"product-highlight-text": {
"props": {
"message": "{highlightName}"
}
}
}
- Example using
product-highlight-wrapper
:
{
"[email protected]:product-highlights": {
"children": ["product-highlights-wrapper"]
},
"product-highlights-wrapper": {
"children": [
"icon-star", // You can add anything inside a product-highlights-wrapper
"product-highlight-text"
]
},
"product-highlight-text": {
"props": {
"message": "{highlightName}"
}
}
}
- Example using the prop
filter
and the proptype
:
{
"[email protected]:product-highlights": {
"props": {
"type": "teaser",
"filter": {
"type": "show",
"highlightNames": ["10% Boleto"]
}
},
"children": ["product-highlight-text"]
},
"product-highlight-text": {
"props": {
"message": "{highlightName}",
"blockClass": "boleto"
}
}
}
store.product
and product-summary.shelf
.
Prop name | Type | Description | Default value |
---|---|---|---|
type |
enum |
Desired type of product highlight to be displayed. Possible values are: collection , promotion , and teaser . collection highlights the product's collection therefore it must be be used in conjuction with the Collection Highlight feature. promotion and teaser should be used when the product is configured with a promotion with highlights, but notice the following: teaser must only be used when the promotion presents restrictions. promotion , in turn, when it does not. |
collection |
filter |
object |
Defines the highlights that should and should not be displayed by the block. | undefined |
collection
maps to the property clusterHighlights
; promotion
to discountHighlights
; and teaser
to teasers
.
filter
object:
Prop name | Type | Description | Default value |
---|---|---|---|
highlightNames |
[string] |
Array of highlight names to be hidden or shown (according to what is defined in the type property) by the product-highlights block. |
undefined |
type |
enum |
Whether the highlights names passed to the highlightNames prop should be displayed or hidden on the UI. Possible values are: hide (hides highlights declared in the highlightNames prop) or show (only shows the highlights declared in the highlightNames prop). |
undefined |
Prop name | Type | Description | Default value |
---|---|---|---|
blockClass |
string |
Block ID of your choosing to be used in CSS customization. | undefined |
message |
string |
Defines the block's default text message to be rendered on the UI. You can also define which text message a block will render on the UI using the admin's Site Editor and the markers prop. |
undefined |
markers |
[string] |
IDs of your choosing to identify the block's rendered text message and customize it using the admin's Site Editor. Learn how to use them accessing the documentation on Using the Markers prop to customize a block's message. Notice the following: a block's message can also be customized in the Store Theme source code using the message prop. |
[] |
Prop name | Type | Description | Default value |
---|---|---|---|
blockClass |
string |
Block ID of your choosing to be used in CSS customization. | undefined |
The product-highlight-text
uses the ICU Message Format, making it possible to fully edit the block's rendered text messages.
When using the message
prop, you won't need to perform any advanced configurations: declare the prop directly in your Store Theme app, passing to it the desired text value to be rendered with the block.
The markers
prop, in turn, requires you to perform an extra configuration in the admin's Site Editor to properly work. When using this prop, do not forget to check out the block's message variables (shown in the table below) and the Using the Markers prop to customize a block's message documentation.
Message variable | Type | Description |
---|---|---|
highlightName |
string |
Highlight name. |
To apply CSS customization in this and other blocks, follow the instructions given in the recipe on Using CSS Handles for store customization.
CSS Handles |
---|
productHighlightText |
productHighlightWrapper |
Data Attributes |
---|
data-highlight-name |
data-highlight-id |
data-highlight-type |
Thanks goes to these wonderful people:
This project follows the all-contributors specification. Contributions of any kind are welcome!