Skip to content
TubePress — free, self-hosted & actively maintained
Developer reference

Theme API reference

TubePress Theme API reference: every global template variable, helper function and class available when building or customising a tube site theme.

This page is the complete reference for everything a theme can use: the global variables injected into every template, the variables specific to each template, and the helper classes available in theme code. If you are building or customising a theme, keep this page open alongside Theme development.

Every template is rendered by ThemeRenderer::render($template, $data). The renderer injects a set of global $_-prefixed variables, merges in the template-specific $data, runs the theme.template_data filter, buffers your template into $content, then loads layout.php.

Global variables

These are available in every template and in layout.php.

Site

VariableTypeDescription
$_templatestringCurrent template name (e.g. 'home', 'video')
$_siteNamestringSite name from settings
$_siteDescriptionstringSite description
$_siteUrlstringSite URL
$_videosPerRowintGrid columns (4, 5 or 6)
$_userarray\|nullLogged-in user, or null
$_footerPagesarrayStatic pages flagged for the footer
$_registrationEnabledboolRegistration toggle
$_ctrEnabledboolCTR ranking toggle

Appearance

VariableTypeDescription
$_siteLogostringLogo filename (in /uploads/branding/)
$_siteFaviconstringFavicon filename
$_siteBackgroundstringBackground image filename
$_siteBackgroundModestring'cover', 'contain' or 'repeat'
$_colorOverridesstring<style> block with CSS custom properties
$_menuSearchboolShow the search bar
$_menuItemsarrayNavigation items (key, label, url, enabled, templates)

Locale

VariableTypeDescription
$_localestringCurrent locale code (e.g. 'en')
$_directionstring'ltr' or 'rtl'
$_isRtlboolRight-to-left language
$_availableLangsarrayAvailable languages
$_langPrefixstringURL prefix (e.g. '/fr' or '')

Video card settings

VariableTypeDescription
$_cardShowDurationboolShow the duration badge
$_cardShowTitleboolShow the video title
$_cardMetaLeftstringLeft meta: 'views', 'likes', 'time', 'none'
$_cardMetaRightstringRight meta (same options)
$_cardGridGapintGrid gap in pixels
$_cardBorderRadiusintCard border radius in pixels
$_cardThumbnailHoverboolThumbnail hover effect
$_cardTitleLinesintTitle lines (1 or 2)

Watch page settings

VariableTypeDescription
$_watchShowViewsboolShow the view count
$_watchShowDurationboolShow the duration
$_watchShowDateboolShow the publish date
$_watchShowLikesboolShow like / dislike
$_watchShowFavoritesboolShow the favorite button
$_watchShowPornstarsboolShow performers
$_watchShowChannelsboolShow channels
$_watchShowCategoriesboolShow categories
$_watchShowTagsboolShow tags
$_commentsEnabledboolComments enabled
These are settings, not magic. Every $_card* and $_watch* value comes straight from the admin Appearance screen, so site owners can re-style your theme without touching code — as long as you read these variables instead of hard-coding.

Template-specific variables

In addition to the globals, each template receives its own data.

home.php

VariableType
$videosarray — video rows
$paginationPagination object
$sortstring — current sort key

video.php

VariableType
$videoarray — full video with categories, tags, performers, channels
$categories, $tags, $performersarray
$commentsarray
$similararray — similar videos
$recommendedarray — recommended videos
$userVotestring\|null — 'like', 'dislike' or null
$isFavoritedbool

category.php / tag.php / performer.php / channel.php

VariableType
$category / $tag / $performer / $channelarray — the entity
$videosarray — video rows
$paginationPagination object
$sortstring

Listing templates

TemplateNotable variables
categories.php$categories — each has video_count; with CTR on, best_video_thumbnail
performers.php$performersvideo_count; with CTR on, best_video_thumbnail, total_ctr, sorted by CTR; $pagination
channels.phpSame shape as performers
search.php$query, $videos, $pagination

Helper classes

These static helpers are available in every template.

ClassKey methods
ThemeRenderer::enqueueCSS($url, $priority), ::enqueueJS($url, $priority), ::partial($name, $data), ::bodyClass(), ::renderCSS(), ::renderJS()
ThemeManager::assetUrl($path), ::themePath(), ::templatePath($t), ::active(), ::info($key)
ImpressionTracker::collect($videoId), ::flush(), ::isBot()
Format::number($n), ::duration($seconds), ::timeAgo($datetime), ::fileSize($bytes)
Pagination->total, ->page, ->totalPages, ->offset, ->hasPrev(), ->hasNext(), ->pages(), ->prevUrl(), ->nextUrl()
Router::url($path), ::csrfField(), ::csrfToken(), ::langPrefix()
HookSystem::doAction($event, ...$args), ::applyFilter($filter, $value, ...$args)
Auth::check(), ::user(), ::id()
Setting::get($key, $default)
__($key, $replacements)Translation helper
url($path)Shortcut for Router::url($path)

The rendering flow

  1. Controller calls the renderer. ThemeRenderer::render('home', ['videos' => $videos, …]).
  2. Globals are injected. The $_-prefixed site, appearance, locale and card/watch variables are added.
  3. Plugins can modify the data. HookSystem::applyFilter('theme.template_data', $data, $templateName) runs.
  4. The template renders. Your template file is buffered into $content.
  5. The layout loads. layout.php receives $content plus all variables.
  6. Impressions flush. ImpressionTracker::flush() sends the batched impression update (CTR).
  7. Cron runs. CronManager::run() executes any due scheduled tasks.

layout.php requirements

A theme's layout.php must do all of the following:

  1. Output the full HTML shell (<!DOCTYPE html></html>).
  2. Include <?= ThemeRenderer::renderCSS() ?> in <head>.
  3. Include <?= $_colorOverrides ?> in <head>.
  4. Echo $content inside <main>.
  5. Include <?= ThemeRenderer::renderJS() ?> before </body>.
  6. Call <?php ImpressionTracker::flush(); ?> before </body> (for CTR).
  7. Call <?php HookSystem::doAction('head.meta'); ?> in <head>.
  8. Call <?php HookSystem::doAction('footer.scripts'); ?> before </body>.

Template fallback

If a template is missing from the active theme, TubePress falls back to the bundled Simply theme. A custom theme therefore only needs to override the templates it actually wants to change — start from one template and grow from there.

Next steps

Still stuck?

Open a ticket from your dashboard and our team will help you out.

Try the live demo → Download TubePress →