# PDF Section Pattern for Product Pages
This guide explains how to add price PDF sections to product pages. The "ราคาสินค้า" (Price) button automatically appears based on whether a `#pricelist` section exists on the page.
## Auto-Detection Behavior
The hero section includes a "ราคาสินค้า" button that is **hidden by default** (`hidden` class). JavaScript in `BaseLayout.astro` automatically:
- **Shows** the button if `#pricelist` section exists on the page
- **Hides** the button if `#pricelist` section does not exist
This means you only need to add the PDF section — the button visibility is handled automatically.
---
## Adding PDF to Existing Product
### Step 1: Add PDF file
Copy the PDF file to `public/documents/` directory.
### Step 2: Add PDF section with `id="pricelist"`
Add this section to the product page (typically at the bottom, before the contact CTA):
```astro
```
### Step 3: Ensure button has correct attributes
The hero button must have:
- `href="#pricelist"` — scrolls to the PDF section
- `data-price-button` — tells JavaScript this is the price button
- `class="hidden"` — starts hidden, JS will remove this if section exists
```astro
ราคาสินค้า
```
---
## Products with PDF Sections (4 pages)
| Product | Route | PDF File |
|---------|------|----------|
| เทอร์โมเบรค Thermobreak | `/เทอร์โมเบรค-thermobreak` | `2026-New Update Thermobreak Price List.pdf` |
| เครื่องเชื่อม HDPE | `/เครื่องเชื่อม-hdpe` | `Price List HDPE.pdf` |
| ฉนวนหุ้มท่อ | `/ฉนวนหุ้มท่อ` | `16 Price List Armaflex 2567.pdf` |
| เม็ดกรู๊ฟ คับปลิ้ง | `/เม็กกรู๊ฟ-คับปลิ้ง` | `Price List MECH_V13-2021 [260864](1).pdf` |
---
## Products WITHOUT PDF Sections
These pages do NOT have a `#pricelist` section, so the "ราคาสินค้า" button will remain hidden:
- `/water-pump`
- `/water-treatment`
- `/วาล์ว-valve`
- `/durgo-avvs`
- `/อุปกรณ์ปรับอากาศ`
- `/grilles`
- `/realflex`
- `/อุปกรณ์ดับเพลิง`
- `/รั้วเทวดา`
- `/ระบบรั้วไวน์แมน`
- And all other product pages not listed above
---
## JavaScript Implementation
The auto-detection script is in `src/layouts/BaseLayout.astro`:
```typescript
document.addEventListener('DOMContentLoaded', () => {
const priceButton = document.querySelector('[data-price-button]');
if (!priceButton) return;
const hasPricelist = document.getElementById('pricelist') !== null;
if (hasPricelist) {
priceButton.classList.remove('hidden');
priceButton.removeAttribute('disabled');
} else {
priceButton.classList.add('hidden');
}
});
```
---
## Adding New Product with PDF
1. Create the product page in `src/pages/`
2. Add hero section with the "ราคาสินค้า" button using `data-price-button class="hidden"`
3. Add the PDF section with `id="pricelist"` at the appropriate location
4. Copy PDF to `public/documents/`
5. The button will automatically appear when the page loads
---
## Testing
After adding a PDF section, verify:
1. Navigate to the product page
2. The "ราคาสินค้า" button should be visible in the hero section
3. Click the button — it should scroll to the `#pricelist` section
4. The PDF link should open correctly
For pages without PDF:
1. Navigate to a product page without a `#pricelist` section
2. The "ราคาสินค้า" button should not be visible