> Add Plandalf to an Astro site in your base layout, then open checkouts from attributes in any page or component.

Source: https://plandalf.com/docs/frameworks/astro

Frameworks

# Astro

Add the Plandalf script to your base layout once, then any element on your Astro pages can open a checkout. It works in `.astro` files and in React, Vue or Svelte islands.

## Add the script

Paste the script before `</body>` in the layout every page uses. Copy your script address from your checkout's **Share** screen (pick **HTML**).

```html
---
const { title } = Astro.props;
---
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>{title}</title>
  </head>
  <body>
    <slot />
    <script is:inline async src="https://YOUR-ORG.plandalf.dev/js/plandalf-sdk.js"></script>
  </body>
</html>
```

`is:inline` tells Astro to leave the tag as it is, so it loads the script from Plandalf instead of bundling it.

## Open a checkout from a button

Add the attribute to any element. It needs no JavaScript of its own, so it works in plain `.astro` files:

```html
<button data-plandalf-present="YOUR-CHECKOUT">Buy Now</button>
```

### From your own code

Queue the call with the stub, so it works before the script has loaded:

```html
<button id="upgrade">Upgrade</button>
<script>
  const w = window as any;
  w.plandalf = w.plandalf || function () { (w.plandalf.q = w.plandalf.q || []).push(arguments); };
  document.querySelector("#upgrade")?.addEventListener("click", () => w.plandalf("present", "YOUR-CHECKOUT"));
</script>
```

See [Open a checkout from code](https://plandalf.com/docs/developers/open-a-checkout).

## Show a checkout on the page

Add an empty element with `data-plandalf-mount`:

```html
<div data-plandalf-mount="YOUR-CHECKOUT" style="min-height: 480px"></div>
```

## Show a deadline timer

Add an empty element with your deadline timer's slug. The script draws the live countdown inside it. To charge the deadline timer's current price, add `data-plandalf-apply-promo` with the same slug to your buy button.

```html
<div data-plandalf-promo="YOUR-PROMO"></div>
<button data-plandalf-present="YOUR-CHECKOUT" data-plandalf-apply-promo="YOUR-PROMO">Buy Now</button>
```

See [Countdowns](https://plandalf.com/docs/promos/countdowns).

## Use a package in an island

In an interactive island, you can use [@plandalf/react](https://plandalf.com/docs/frameworks/react), [@plandalf/vue](https://plandalf.com/docs/frameworks/vue) or [@plandalf/svelte](https://plandalf.com/docs/frameworks/sveltekit). Set up the provider or context inside each island that uses the package. Astro islands have separate component trees, so they don't share framework context.

## Check it's working

1.  ### Open the page
    
    If you used the hosted script, type `typeof window.plandalf` in the browser console. Look for `"function"`.
    
2.  ### Click your button
    
    Plandalf should display your checkout over the page.
    
3.  ### Make a test purchase
    
    Add `localhost` and your staging site in Plandalf under **Settings → Advanced → Test domains**. Checkouts there use Stripe test cards. See [Test mode](https://plandalf.com/docs/get-started/test-mode).
    

## If it isn't working

-   With view transitions (`<ClientRouter />`), Astro swaps the page body when you navigate, and buttons on the new page may not open. Add `data-astro-reload` to links that lead to pages that sell, so those pages load in full.
-   Without `is:inline`, Astro may try to bundle the script. Keep the attribute.
-   Add `data-debug="true"` to the script tag and the console logs each step the script takes.

See [Troubleshooting](https://plandalf.com/docs/help/troubleshooting).

Something wrong or missing? Email [hello@plandalf.com](mailto:hello@plandalf.com).
