---
title: Templates
date: 2026-06-13T16:13:00+01:00
author: John Henry Donovan
canonical_url: "https://johnhenry.ie/plugins/pricing-rules-relationship/docs/guide/templates"
section: Plugins
---
esc

↑↓ to navigate↵ to selectesc to close

Menu On this page 

- [Return to top](#)

Documentation

Documentation

# Templates

## The Pricing Rules Relationship variable

To use, first create a Twig variable for your Pricing Rules Relationship field. In this example we are using the field handle `salesRelationship`, replace this with whatever handle you gave the field when you created it.

```twig
{% set saleRelationships = entry.salesRelationship %}
```

Then pass the variable to the `getSaleIds` function using the `craft.pricingRulesRelationship` variable.

```twig
{% set productIds = craft.pricingRulesRelationship.getSaleIds(saleRelationships) %}
```

This gives you an array of product IDs related to the Pricing Rules selected in the field. Expired rules are excluded automatically.

`getSaleIds()` also takes an optional second argument, `hasStock`, if you want to exclude out-of-stock products too (it defaults to `false`, so out-of-stock products are included unless you opt in):

```twig
{% set productIds = craft.pricingRulesRelationship.getSaleIds(saleRelationships, true) %}
```

Example dump of the array:

```javascript
array:2 [▼
  0 => 3
  1 => 27
]
```

You can then pass into the [products query](https://craftcms.com/docs/commerce/5.x/system/products-variants.html#querying-products) using the [id parameter](https://craftcms.com/docs/commerce/5.x/system/products-variants.html#product-id).

```twig
{# Create a product query with the 'type' and 'limit' parameters #}
{% set newProducts = craft.commerce.products()
  .id(productIds)
  .all() %}

{# Display the products #}
{% for product in newProducts %}
  <h2>{{ product.title }}</h2>
  {{ product.summary|md }}
  <a href="{{ product.url }}">Learn more</a>
{% endfor %}
```

## Special Offers Page Example

Here's a fuller example of a Special Offers Page, with pagination thrown in:

```twig
{% extends 'shop/_private/layouts' %}

{% set saleRelationships = entry.salesRelationship %}{# replace with your field handle #}
{% set productIds = craft.pricingRulesRelationship.getSaleIds(saleRelationships) %}

{% block main %}
   <!-- Template: {{ _self }}.twig -->
   <div class="sm:flex">
      <div class="sm:w-1/3 w-full">
         <h1 class="text-3xl block sm:inline">
            {{entry.title}}
         </h1>
         {{ entry.summary }}
      </div>
   </div>
   {% paginate craft.commerce.products().limit(6).id(productIds) as pageInfo, pageProducts %}
   
   {{ include('shop/products/_includes/grid', {
      products: pageProducts
   }) }}

   {{ include('shop/products/_includes/pagination', {
      products: pageProducts,
      pageInfo: pageInfo
   }) }}
{% endblock %}
```

Important If the Pricing Rule has expired, it won't show in the template. Store Managers don't need to worry about manually turning off Pricing Rules Relationships. Out-of-stock products stay visible unless you pass `hasStock: true` to `getSaleIds()`.

On this page
