# Bludit Pro 3.22.0 – Theme Architect Rulebook

---

## Flash Version: Dense Template Quick‑Reference

### $WHERE_AM_I Values & Content Mapping

| $WHERE_AM_I | Content Available | Typical Action |
|-------------|-------------------|----------------|
| `'home'` | `$content` (list) + possibly `$page` (static homepage) | Loop `$content`; show `$page->content()` if `$page` exists. |
| `'blog'` | `$content` (list) | Loop `$content` (sticky merged). |
| `'page'` | `$page` (single page) | `$page->content()`, meta, comments area. |
| `'tag'` | `$content` (pages with tag) | Loop with tag heading. |
| `'category'` | `$content` (pages in category) | Loop with category heading. |
| `'search'` | `$content` (search results) | Loop, no page object. |

### Essential Template Variables

```php
// Globals always available
$WHERE_AM_I          // string
$page                // Page object or false
$content             // array of Page objects
$staticContent       // array of Page objects (static pages)
$site                // Site object
$url                 // Url object
$L                   // Language object
$themePlugin         // Companion plugin or false

// Helpers
Theme::metaTagTitle()
Theme::metaTagDescription()
Theme::plugins('hookName')
Paginator::numberOfPages()
Paginator::currentPage()
Paginator::nextPageUrl()
```

### If/Else Logic Boilerplate for Theme index.php

```php
<!DOCTYPE html>
<html lang="<?php echo Theme::lang() ?>">
<head>
    <?php Theme::plugins('siteHead') ?>
</head>
<body>
    <?php Theme::plugins('siteBodyBegin') ?>

    <?php if ($WHERE_AM_I == 'page' && $page): ?>
        <article>
            <h1><?php echo $page->title() ?></h1>
            <?php Theme::plugins('pageBegin') ?>
            <?php echo $page->content() ?>
            <?php Theme::plugins('pageEnd') ?>
        </article>

    <?php elseif (in_array($WHERE_AM_I, ['home','blog','tag','category','search'])): ?>
        <?php if (!empty($content)): ?>
            <?php foreach ($content as $Post): ?>
                <div class="post">
                    <h2><a href="<?php echo $Post->permalink() ?>"><?php echo $Post->title() ?></a></h2>
                    <div><?php echo $Post->contentBreak() ?></div>
                    <?php if ($Post->readMore()): ?>
                        <a href="<?php echo $Post->permalink() ?>">Read more</a>
                    <?php endif ?>
                </div>
            <?php endforeach ?>
        <?php else: ?>
            <p><?php echo $L->get('No posts found') ?></p>
        <?php endif ?>

        <?php if (Paginator::numberOfPages() > 1): ?>
            <nav><?php echo Paginator::bootstrap_html() ?></nav>
        <?php endif ?>

    <?php elseif ($url->notFound()): ?>
        <h1>404 - Page Not Found</h1>
        <?php if ($page) echo $page->content() ?>

    <?php endif ?>

    <?php Theme::plugins('siteSidebar') ?>
    <?php Theme::plugins('siteBodyEnd') ?>
</body>
</html>
```

### Minimal Hooks Map
Insert these exactly where indicated:

- `siteHead` → `<head>` after charset/meta
- `siteBodyBegin` → after `<body>`
- `siteBodyEnd` → before `</body>`
- `siteSidebar` → wherever sidebar should appear
- `pageBegin` → just before `$page->content()`
- `pageEnd` → just after `$page->content()`

### Pagination Quick‑copy
```php
if (Paginator::numberOfPages() > 1) {
    echo '<nav class="paginator">';
    if (Paginator::showPrev()) {
        echo '<a href="'.Paginator::previousPageUrl().'">Previous</a>';
    }
    for ($i=1; $i<=Paginator::numberOfPages(); $i++) {
        if ($i == Paginator::currentPage()) {
            echo '<span>'.$i.'</span>';
        } else {
            echo '<a href="'.Paginator::numberUrl($i).'">'.$i.'</a>';
        }
    }
    if (Paginator::showNext()) {
        echo '<a href="'.Paginator::nextPageUrl().'">Next</a>';
    }
    echo '</nav>';
}
```

### Theme Language Utility
```php
// In en.json
{ "theme-data": {...}, "read-more": "Read more" }

// In template
<?php echo $L->get('read-more') ?>
```
Use `$L->get()` for all hard‑coded strings; this way the theme is translatable.

### Companion Plugin Read
```php
<?php $primaryColor = ($themePlugin) ? $themePlugin->getValue('primaryColor') : '#000' ?>
```

### Page Template Override
```php
<?php
if ($page && $page->template()) {
    include('page-'.$page->template().'.php');
} else {
    include('page-default.php');
}
?>
```

---

*This Rulebook is based on the Bludit Pro 3.22.0 patched codebase and does not replicate the full developer reference. For class methods and deeper internals, refer to the main Pro 3.22.0 Developer Reference.*