Template Code

Every section template in Glood.AI consists of several core files that work together to create a complete recommendation section. We use the liquidJS library to render Liquid code at the client side. For any queries regarding Liquid-specific data structures, filters, or tags, please refer to the Shopify Liquid documentation.

Core Parts

1. Section Template

The main template that defines the HTML structure and dynamic content rendering. It uses data structures defined in the Object Definitions.

Dynamic Implementation

Liquid Filters

Our filters used in the template:

FilterPurposeParametersOutputExample
moneyPrice formattingNumber/String, money_format: Override default formatFormatted price19.99 | money"$19.99"
optimize_imageImage optimizationURL, width: Desired width, height: Desired height, crop: Crop modeOptimized URLproduct.image | optimize_image: width: 300, height: 300
tracking_urlAdd trackingProduct, section (required): Section context, ref_product_id: Reference product IDURL with paramsproduct | tracking_url: section
section_discountFormat discountSection, money_format: Price format, locale: Language codeDiscount stringsection | section_discount: money_format: shop.money_format

2. JS Hooks

The JavaScript hooks system provides a powerful way to customize and extend section behavior. These hooks are called at specific points in the section’s lifecycle, allowing you to implement custom functionality and handle various events.

Core callBacks available

Method NameParametersDescriptionReturn
initSwiper(Swiper, templateSettings, container, params, defaultSettings, utils)Initializes carousel functionalitySwiper instance
onSectionInit(args, cb, gloodUtils)Called when section initializesvoid
onSectionRenderComplete(args, utils)Called after section renderingvoid
onVariantChange(args, utils)Handles variant selectionvoid
onSwatchChange(args, utils)Handles swatch selectionvoid
validateCartOperation(payload, recommendation, utils)Validates cart operations{payload, error}
onCartOperationComplete(args, utils)Called after cart operationvoid
onProductDataReceived(args, utils)Handles product datavoid
getProductDetailsQuery(recommendation, glood)Returns GraphQL querystring
transformProductData(product, recommendation)Transforms product dataobject
onSectionRendered(section, products)Fired when section is fully renderedvoid
onProductClick(section, products, productId)Fired when product is clickedvoid
onAddToCart(section, products, items, response)Fired on successful cart additionvoid
onVariantSelected(section, products, productId, variantId)Fired when variant is selectedvoid

Example Implementation

// Example: Carousel Initialization Hook
initSwiper: (Swiper, templateSettings, container, params) => {
    const carouselContainer = container.querySelector('._gai-crz-cnt');
    if (!carouselContainer) return;
    
    return new Swiper(carouselContainer, {
        slidesPerView: templateSettings.breakpoints.small.cardsPerView,
        spaceBetween: templateSettings.breakpoints.small.gutter
    });
}

// Example: Variant Change Hook
onVariantChange: (args, utils) => {
    const { variant, product, container } = args;
    const priceElement = container.querySelector('._gai-prod-prc');
    if (priceElement && variant.price) {
        priceElement.textContent = utils.formatMoney(variant.price);
    }
}

3. CSS Template

The CSS template system provides a flexible way to style your recommendation sections. It uses Liquid templating for dynamic styling based on section settings and configuration. Both section template and CSS template have access to the same template object. For a complete reference of available objects and their structure, see Template Objects.

Structure and Organization

The CSS is organized by components and breakpoints:

  • Base styles for mobile-first approach
  • Tablet styles (default: 768px)
  • Desktop styles (default: 1024px)

NOTE:

  1. The CSS follows a mobile-first approach, where base styles are written for mobile devices and then progressively enhanced for larger screens through media queries. This ensures optimal performance and maintainability while providing a solid foundation for responsive design.
  2. These breakpoint values are customizable through the template settings. For detailed configuration options, see settings.breakpoints[].screenSize in the Template Object documentation.

CSS Class Reference

Class NamePurposeProperties ControlledExample Usage
._gai-gridMain product grid container- Grid layout (grid-template-columns)
- Gap between items
- Responsive columns
Controls overall product grid layout
._gai-sec-titSection title styling- Font size
- Text alignment
- Line clamping
- Display properties
- Webkit box orientation
Main section heading appearance
._gai-prod-cardIndividual product card- Background color
- Font family
- Max width (for bundle layout)
Container for each product
._gai-prod-imgProduct image container- Aspect ratio
- Object-fit
Product image display
._gai-prod-img-wrapImage wrapper- Aspect ratioControls image container proportions
._gai-prod-titProduct title- Color
- Font weight
- Line clamping
- Text alignment
- Font size
- Font family
Product name styling
._gai-prod-vndrVendor name- Font size
- Display properties
Brand/vendor name display
._gai-prod-vndr--above-titleVendor name above title- Display (block/none)Vendor positioning above title
._gai-prod-vndr--below-titleVendor name below title- Display (block/none)Vendor positioning below title
._gai-prod-prcProduct price- Color
- Font family
- Font size
Main price display
._gai-prod-prc--compare-atCompare-at price- Color
- Display
- Visibility conditions
Original/compare price styling
._gai-atc-btnAdd to cart button- Background color
- Text color
- Border
- Border radius
- Disabled state
Add to cart button styling
._gai-dis-cntDiscount container- Justification
- Background color
- Display (flex/none)
Discount information wrapper
._gai-dis-txtDiscount text- Color
- Font size
Discount amount/percentage text
._gai-disDiscount badge- Background color
- Text color
- Opacity
Discount label styling
._gai-containerMain section container- Background colorSection wrapper styling
._gai-bundle-productsBundle products grid- Grid template columnsLayout for bundled products
._gai-skl-atcSkeleton add to cart- Display visibilityLoading state for add to cart
._gai-bndl-secBundle section- Justify contentBundle section layout
._gai-amz-titAmazon bundle title- Text alignmentTitle for Amazon-style bundles

Label Classes

Special classes for product status and badges:

Class NamePurposeCustomizable Properties
._gai-oosOut of stock badge- Background color
- Text color
._gai-bestsellerBestseller badge- Background color
- Text color
._gai-newNew product badge- Background color
- Text color
._gai-trendingTrending item badge- Background color
- Text color

Responsive Behavior

The code includes media queries for different screen sizes:

/* Mobile (default) */
[data-gai-section-id="{{ section_id }}"] ._gai-grid {
  grid-template-columns: repeat({{- settings.breakpoints.small.cards_per_view -}}, 1fr);
  gap: {{ settings.breakpoints.small.gutter }}px;
}

/* Tablet */
@media (min-width: {{ settings.breakpoints.medium.screen_size }}px) {
  /* Tablet-specific styles */
}

/* Desktop */
@media (min-width: {{ settings.breakpoints.large.screen_size }}px) {
  /* Desktop-specific styles */
}

Support

For help with template customization or troubleshooting, contact our support team at support@glood.ai