> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crossmint.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Mint to Specific Template

> Specify which NFT template to mint from during checkout (for Managed collections only)

## Overview

When minting NFTs from a collection with multiple templates, you can specify which template to mint to using your Crossmint integration. This feature must be explicitly enabled in the Crossmint Console.

This gives you control over exactly which template gets minted when processing a purchase, rather than relying on random template selection.

## Supported Collection Types

Selecting a specific token template for purchase is supported on:

* EVM ERC-721 and ERC-1155 collections
* Solana collections

In the following chains, tokens will always be selected randomly:

* Aptos collections

## Enabling Template Minting

Follow these steps in the Crossmint Console to enable template-specific minting:

1. Go to your collection in the Crossmint Console
2. Navigate to the "Checkout" section
3. Under "NFT Template Settings", enable "Mint to specific NFT Template"

<img src="https://mintcdn.com/crossmint/z7jtH2QvDk5-6XiW/images/payments/advanced/mint-to-specific-template.png?fit=max&auto=format&n=z7jtH2QvDk5-6XiW&q=85&s=aa85d0de4d6f22ec035efc5654fff6b7" alt="" width="1380" height="227" data-path="images/payments/advanced/mint-to-specific-template.png" />

## Using Template IDs

<Warning>
  If template-specific minting is disabled for your collection and you pass a template ID in the collection locator,
  the request will select a template randomly. Make sure to enable this feature in the Console before using template IDs.
</Warning>

<Note>
  To see all your available templates, navigate to the "NFTs" section in the Console for your managed collection.

  You can also get all your available templates for a collection using the [NFT Template API](/api-reference/minting/template/get-all-templates).
</Note>

Once enabled, specify which template to mint by adding the template ID to your collection locator. The collection locator format without templateId is:

```
crossmint:<collectionId>
```

and with templateId is:

```
crossmint:<collectionId>:<templateId>
```

The `templateId` portion is optional with mint to specific template enabled. If omitted, the system will use your collection's default minting behavior.

Here's how to implement template minting in your integration:

<Tabs>
  <Tab title="Embedded Checkout v3">
    Add the template ID to your collection locator string:

    ```jsx theme={null}
    <CrossmintProvider apiKey={clientApiKey}>
      <CrossmintEmbeddedCheckout
        lineItems={{
          // For a specific template:
          collectionLocator: `crossmint:${collectionId}:${templateId}`,
          // Or for random template selection:
          // collectionLocator: `crossmint:${collectionId}`,
          callData: {
            totalPrice: "0.001",
            quantity: 1,
          },
        }}
      />
    </CrossmintProvider>
    ```
  </Tab>

  <Tab title="Headless Checkout">
    Add the template ID to your collection locator string when creating an order:

    ```json theme={null}
    {
      "payment": {
        "method": "stripe-payment-element"  // or your preferred payment method
      },
      "lineItems": [
        {
          // For a specific template:
          "collectionLocator": "crossmint:<collectionId>:<templateId>",
          // Or for random template selection:
          // "collectionLocator": "crossmint:<collectionId>",
          "callData": {
            "totalPrice": "0.001"
          }
        }
      ]
    }
    ```
  </Tab>
</Tabs>

## Error Handling

When implementing template minting, handle these potential error cases:

1. **Invalid Template ID**

   * Error message: Transaction fails with template validation error
   * Occurs when: The specified template ID doesn't exist in the collection
   * Resolution: Verify the template ID exists in your collection

2. **No Code Storefront**
   * Mint to specific template is not currently supported on No Code Storefront. If you'd like this feature, please reach out to your CSE rep

Here's how to handle these errors in your code:

<Tabs>
  <Tab title="Embedded Checkout v3">
    ```jsx theme={null}
    try {
      <CrossmintProvider apiKey={clientApiKey}>
        <CrossmintEmbeddedCheckout
          lineItems={{
            collectionLocator: `crossmint:${collectionId}:${templateId}`,
            callData: {
              totalPrice: "0.001",
              quantity: 1,
            },
          }}
          onError={(error) => {
            if (error.message.includes(`Template ${templateId} was not found in collection`)) {
              // Invalid template ID
              throw new Error("Invalid template ID provided");
            }
            throw error
          }}
        />
      </CrossmintProvider>
    } catch (error) {
      // Handle other errors
      console.error("Minting failed:", error);
    }
    ```
  </Tab>

  <Tab title="Headless Checkout">
    ```typescript theme={null}
    try {
      const response = await fetch("/api/create-order", {
        method: "POST",
        body: JSON.stringify({
          lineItems: [
            {
              collectionLocator: `crossmint:${collectionId}:${templateId}`,
              callData: {
                totalPrice: "0.001"
              }
            }
          ]
        })
      });

      if (!response.ok) {
        const error = await response.json();
        if (error.message.includes(`Template ${templateId} was not found in collection`)) {
          // Invalid template ID
          throw new Error("Invalid template ID provided");
        }
        throw error;
      }
    } catch (error) {
      // Handle the error appropriately
      console.error("Order creation failed:", error);
    }
    ```
  </Tab>
</Tabs>
