Hand-written Includes in-depth notes
Thumbnail URL content_thumb
Used inside components
Returns the content thumbnail URL and falls back to a default image when there is none (an optional placeholder).
content_thumb($item, $default = '', $allowPlaceholder = false)
Pages Home List pages Detail pages Search
How do I read these repository paths?
All paths are relative to the site root. Open core/tpl_functions.php at line 408 to see the definition of content_thumb(). The "core method" is what the tag actually forwards to: a template writes content_list(...) and the core runs Tpl::contentList(...).
1. Fill in parameters, get the code Edit any field and the result below updates instantly; press Copy and paste it into a template. It also works without JavaScript: press Generate and the server recomputes it.
click the title to collapse / expand
Now generating: content_thumb
This is the real rendering of the page (real header, container, this tag output, real footer). It reloads when you change a parameter.
Refreshing…
This is the server-computed default; it updates as you edit any parameter and the preview on the right is re-rendered too. It also works without JavaScript: fill the form and press Generate.
2. Full parameter table 3 parameters, one per row; scroll sideways on narrow screens.
click the title to collapse / expand
| Parameter | Type | Default | Description |
|---|---|---|---|
item |
array |
required / as needed | Content row; uses thumb, otherwise the first entry of images. |
default |
string |
'' | URL returned when there is no usable image; empty by default, never auto-filled. |
allowPlaceholder |
bool |
false | false (default): a generic placeholder.* image returns the default value. |
3. Examples Every example can be copied as-is; the later ones are more advanced.
click the title to collapse / expand
Minimal
One line reads the thumbnail URL; it yields an empty string when the row has no image, so use it only where images are guaranteed.
<img src="<?= e(content_thumb($item)) ?>" alt="<?= e(field($item, 'title')) ?>" loading="lazy">
Guard and fall back to text
Rows without an image fall back to a gradient placeholder, and an img with an empty src never reaches the browser.
<?php $ryThumb = (string)content_thumb($item); ?>
<?php if ($ryThumb !== ''): ?>
<img src="<?= e($ryThumb) ?>" alt="<?= e(field($item, 'title')) ?>" loading="lazy">
<?php else: ?>
<span class="ry-thumb-placeholder" aria-hidden="true"></span>
<?php endif; ?>
Fixed fallback and demo placeholder
The second argument supplies a fixed cover image; for a hero image that must always show, pass true as the third argument instead.
<?php $ryCover = (string)content_thumb($item, '/assets/img/cover-default.png'); ?>
<a class="ry-card" href="<?= e(content_url($item)) ?>">
<img src="<?= e($ryCover) ?>" alt="<?= e(field($item, 'title')) ?>">
</a>
4. What it does / when to use it
Use it for every image on a list card, a related items block, or a search result, wherever a missing picture must not break the layout. It takes three chores off the template: it falls back to the first gallery image when no thumbnail exists, it hides the shared demo placeholder by default so a page of cards does not repeat one photo, and it appends a file modification fingerprint so a re-uploaded image is not served from a stale browser cache. Do not use it for the hero image on a detail page, for original-size output, for custom cropping, or for a lightbox; read the image field directly in those cases.
5. Which pages it belongs on This is the question clients actually ask: "I am building the home page / a list page / a detail page — which tags do I use?"
click the title to collapse / expand
| Page | What that page is | What this tag does there |
|---|---|---|
| Home | Home page: hero, category blocks, latest content |
On the home page it usually sits in the hero, a category block, or a latest/featured section. You use it to: Use it for every image on a list card, a related items block, or a search result, wherever a missing picture must not br |
| List pages | Category list pages: listing, filters, pagination |
On a list page it lives in the list container or right next to the pagination bar. You use it to: Use it for every image on a list card, a related items block, or a search result, wherever a missing picture must not br |
| Detail pages | Content detail pages: body, specs, related items |
On a detail page it goes in the body area or in the related-items sidebar. You use it to: Use it for every image on a list card, a related items block, or a search result, wherever a missing picture must not br |
| Search | Search results: highlighted snippets, result list |
On the search page it appears in the result list or in the highlighted snippet. You use it to: Use it for every image on a list card, a related items block, or a search result, wherever a missing picture must not br |
Clicking a page name jumps to every tag for that page in the reference (the "By page" filter there). This page always shows everything about the tag, whatever that filter is set to.
6. How to use it (step by step)
- Read it once into a variable inside the loop, $ryThumb = (string)content_thumb($item);, instead of calling it twice in the same markup.
- Decide what to render before printing. An empty string means the row has neither a thumbnail nor a gallery image, so render a text card or a gradient placeholder rather than an img with an empty src, which makes the browser request the current page again and floods the console with errors.
- Pass a fixed fallback image as the second argument when the design needs one, for example content_thumb($item, '/assets/img/cover-default.png'); without it the tag returns an empty string and leaves the placeholder to your markup.
- Set the third argument to true only when the shared demo placeholder must be displayed: content_thumb($item, '', true). That switch exists for the hero image on a detail page, so leave it alone in lists.
- Wrap the output in e(), and add a real alt value, usually the title field, together with loading="lazy" for accessibility and first paint speed.
7. Common pitfalls
- Printing the img tag without branching on the result. Both a missing image and a filtered demo placeholder produce an empty string, so you must really use the else branch for a text or gradient placeholder, or the page shows a broken image.
- Comparing the return value as a plain string. The URL may carry a cache fingerprint such as ?v=1234567, so an equality check on two rows to test whether they share one image never matches; strip anything after the question mark before comparing.
- Passing allowPlaceholder as true on a list page: the demo placeholder repeats on every card, which looks like a site without images and suggests that rows are illustrated when they are not.
- Using it for the hero image on a detail page: it follows thumbnail rules and adds the fingerprint, so switch to field($item, 'image') for a lightbox, original dimensions, or a srcset.
Note from the reference table Correction: it does no resizing at all; it only adds a ?v= mtime fingerprint, skipped when the file is absent. The example's thumb() does not exist in templates - use content_thumb().
?v= mtime fingerprint, skipped when the file is absent. The example's thumb() does not exist in templates - use content_thumb().8. Real rendered output This section was rendered once on the server with this site real data; it is not a mock-up.
click the title to collapse / expand
The thumbnail URL (the real one when the row has an image; otherwise the rule of content_thumb($item, '', false) applies).
Loading the code…
9. Where it already appears in your templates Grouped by components / page templates / template packs; the data comes from a script scan.
click the title to collapse / expand
Components 91 files / 105 calls 89% of tag calls live in components
-
templates/_shared/components/detail-content-gallery-portfolio.php×2 lines 55, 259 -
templates/_shared/components/detail-content-news-media.php×2 lines 72, 553 -
templates/_shared/components/detail-content-product-showcase.php×2 lines 167, 840 -
templates/_shared/components/detail-content-video-cinema.php×2 lines 41, 351 -
templates/_shared/components/detail-content-video-player.php×2 lines 59, 692 -
templates/_shared/components/detail-content-video.php×2 lines 556, 683 -
templates/_shared/components/detail-content.php×2 lines 109, 145 -
templates/_shared/components/home-cases-wall.php×2 lines 153, 180
Click "See this code + preview": the left shows the real code around that call site (±12 lines, call line highlighted) and the right renders a real page preview with the current parameters.