Hand-written Includes in-depth notes
Asset URL theme_asset
No call site in this site yet
Return the URL of an asset inside the current template pack with its version number, for referencing custom images and fonts.
theme_asset($path)
Pages Home List pages Detail pages Single pages Site-wide (system)
How do I read these repository paths?
All paths are relative to the site root. Open core/tpl_functions.php at line 40 to see the definition of theme_asset(). 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: theme_asset
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 1 parameters, one per row; scroll sideways on narrow screens.
click the title to collapse / expand
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
string |
required / as needed | Path under the pack's assets/ dir, such as img/bg.jpg; omitting it errors. |
3. Examples Every example can be copied as-is; the later ones are more advanced.
click the title to collapse / expand
Minimal
A pack image: the path is relative to the assets directory and the output is escaped.
<img src="<?= e(theme_asset('img/pattern.png')) ?>" alt="">
Common: stylesheet and script for one page
Keep one-page styles and scripts in their own files instead of the site-wide theme.css and theme.js.
<head>
<?= tpl_head() ?>
<?= theme_css() ?>
<link rel="stylesheet" href="<?= e(theme_asset('css/landing.css')) ?>">
</head>
<body class="ry-site">
<?= theme_js() ?>
<script src="<?= e(theme_asset('js/landing.js')) ?>" defer></script>
</body>
Advanced: preloading a pack font
The font URL carries the same version fingerprint, and the crossorigin attribute is required or the browser downloads the font twice.
<head>
<?= tpl_head() ?>
<link rel="preload" as="font" type="font/woff2" crossorigin
href="<?= e(theme_asset('fonts/brand.woff2')) ?>">
</head>
4. What it does / when to use it
Use it whenever a template references an image, a font, an icon, a single-page stylesheet or a page script that ships inside a template pack. The returned URL carries the application version plus the file modification time, so a replaced file busts the cache with no manual version bump. Resolution goes pack first and shared second: a file under the current pack assets directory wins, and the same path under templates/_shared/assets/ is used when the pack has none, which means shared images live in exactly one place. Do not use it for images or attachments uploaded through the admin, since those live in the upload area rather than in a pack, and do not use it inside a CSS file, because CSS does not execute PHP.
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 whenever a template references an image, a font, an icon, a single-page stylesheet or a page script that ships in |
| 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 whenever a template references an image, a font, an icon, a single-page stylesheet or a page script that ships in |
| 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 whenever a template references an image, a font, an icon, a single-page stylesheet or a page script that ships in |
| Single pages | One-off pages such as About or Contact |
On a single page (About, Contact) it sits inside the content block. You use it to: Use it whenever a template references an image, a font, an icon, a single-page stylesheet or a page script that ships in |
| Site-wide (system) | Header, footer, head, styles and scripts — every page template needs them |
It is a system tag written once per page template, inside the page shell (head, header, footer, scripts). You use it to: Use it whenever a template references an image, a font, an icon, a single-page stylesheet or a page script that ships in |
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)
- Put the file under the pack assets directory, for example assets/img/hero.jpg. Assets shared by several packs go in templates/_shared/assets/ and are picked up automatically.
- Call
<?= e(theme_asset('img/hero.jpg')) ?> in the template. The path is resolved relative to the pack assets directory, so leave the leading assets/ off.
- Always wrap the call in e() when it goes into an HTML attribute. The return value is a raw URL, and an unescaped quote or ampersand truncates the attribute and breaks the markup around it.
- When the same URL is needed twice, for example in a preload hint and in the image tag, store it in a variable first so both strings match exactly and the browser downloads the file only once.
- Copy the generated URL into the browser address bar to confirm it resolves. The tag never checks whether the file exists, so a wrong path still yields a URL, it just returns 404.
<?= e(theme_asset('img/hero.jpg')) ?> in the template. The path is resolved relative to the pack assets directory, so leave the leading assets/ off.7. Common pitfalls
- Writing the path as assets/img/bg.jpg: the tag joins it onto the pack assets directory and looks for assets/assets/img/bg.jpg. Nothing warns you, the page simply returns a 404 URL and the image never shows. The correct form is img/bg.jpg.
- Skipping e(): the URL lands in the attribute unescaped, so a quote or a query string truncates the attribute and the following tags show up as visible text on the page.
- Using it for images or attachments from the upload area: those files are not inside the template pack, so the path can never resolve and the request 404s. Use the decorated address on the content row instead.
- Writing theme_asset() inside a pack CSS file: CSS is not parsed by PHP, so the literal text stays in the stylesheet and the background image disappears. Use a relative path such as url(../img/bg.jpg) in pack styles.
- Expecting a missing file to raise an error: the call performs a pack lookup and a shared lookup and then returns a URL either way. After renaming or moving an asset, open the generated URL once to confirm.
Note from the reference table No default: omitting the argument is a fatal error, not an empty string. The path is relative to the pack's assets/ dir, so the documented example assets/img/pattern.png resolves to a nested assets/assets path that always 404s; use img/pattern.png instead. A path missing from the pack falls back to templates/_shared/assets/, and if both miss, the pack path is returned anyway.
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
It belongs to the document <head>: rendered on its own it is just a set of references that only make sense inside a <head>. Dropping it into this preview would show you raw <link> / <script> source and nothing usable. Copy it into your page template instead (right after <head>).
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
No call site for this tag in this site templates yet.
At a glance
theme_asset
Home / List pages / Detail pages / Single pages / Site-wide (system)