⌘K

Partials & functions

Partials

Partials are optional PHP fragments in theme/{active}/partials/. They let you customize card HTML without touching core PHP functions.

render_article_card($article)
  ↳ Looks for theme/{active}/partials/article-card.php
      → Found    : uses the partial with injected variables
      → Not found: uses the default built-in rendering

No error is thrown if a partial is missing — the built-in fallback is used automatically.

partials/article-card.php

VariableTypeDescription
$articlearrayIndex data: title, slug, date, tags, image, summary
$article_linkstringPre-calculated full article URL
<article class="article-card">
    <?php if (!empty($article['image'])): ?>
    <div class="card-image">
        <a href="<?php echo $article_link; ?>">
            <img src="<?php echo getBaseUrl() . htmlspecialchars($article['image']); ?>"
                 alt="<?php echo htmlspecialchars($article['title']); ?>">
        </a>
    </div>
    <?php endif; ?>
    <div class="card-body">
        <h3><a href="<?php echo $article_link; ?>"><?php echo htmlspecialchars($article['title']); ?></a></h3>
        <p><?php echo get_article_summary($article); ?></p>
        <a href="<?php echo $article_link; ?>" class="read-more"><?php echo __t('read_more'); ?></a>
    </div>
</article>

partials/project-card.php

VariableTypeDescription
$projectarrayProject data
$project_linkstringFull project URL
$card_classstringPre-calculated CSS classes

Helpers available in partials

getBaseUrl()                          // Base URL with trailing slash
cleanUrl($type, $slug, $page, $cat)   // Generate any CMS URL
url_slug($type)                       // Localized URL prefix
sanitizeSlug($string)                 // URL-safe slug
format_date($date)                    // Date formatted per site settings
__t($key)                             // Translation via active locale
get_article_summary($article)         // Summary or auto-generated clean excerpt
_clean_excerpt($html, $length)        // Raw excerpt without shortcodes/HTML
loadConfig()                          // Site settings (use sparingly)

functions.php

Load order

core/functions.php
  ├── core-functions.php
  ├── data-functions.php
  ├── render/theme-api.php  →  tf-markdown, tf-shortcodes, tf-cards, tf-navigation, tf-page
  ├── data-layer.php
  ├── plugin-api.php
  └── lang-cache.php
theme/{active}/functions.php   ← your file, loaded last

What you can do

// Define helper functions
function mytheme_body_class(): string {
    $classes = ['theme-mytheme'];
    $type = $_GET['type'] ?? '';
    $slug = $_GET['slug'] ?? '';
    if (empty($type) && empty($slug)) { $classes[] = 'is-home'; }
    elseif (!empty($slug))             { $classes[] = 'is-single'; }
    else                               { $classes[] = 'is-list'; }
    return implode(' ', $classes);
}

// Pre-fetch sorted data
$GLOBALS['sorted_articles'] = [];
$__articles = sl_load_index('article');
if (!empty($__articles)) {
    usort($__articles, fn($a, $b) => strcmp($b['date'] ?? '', $a['date'] ?? ''));
    $GLOBALS['sorted_articles'] = $__articles;
}
unset($__articles);
ℹ️

Use sl_load_index('article') rather than $GLOBALS['data']['article'] in functions.php — at this point in the bootstrap, $GLOBALS['data'] is not yet defined.

What you cannot do

  • Redefine a CMS function (render_article_card, cleanUrl, etc.) — PHP raises a fatal redeclaration error. Use a partial instead.
  • Use template variables ($item, $pageTitle, etc.) — they don't exist yet at this point in the request.