Welcome to Genhike Sports

Scripts

← Back to the tag reference

Hand-written Includes in-depth notes

Scripts theme_js Used in page templates 21 host files / 21 calls

Render the script tag of the current template pack; it must be placed before .

theme_js()

Pages Site-wide (system)

Used in
Site-wide (system)
Defined in
core/tpl_functions.php:87
Core method
(no X::y() forwarding call detected)
How do I read these repository paths?

All paths are relative to the site root. Open core/tpl_functions.php at line 87 to see the definition of theme_js(). 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

This tag takes no parameters.

Generated code

Now generating: theme_js

Real page previewOpen in new window

This is the real rendering of the page (real header, container, this tag output, real footer). It reloads when you change a parameter.

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.

3. Examples Every example can be copied as-is; the later ones are more advanced.

click the title to collapse / expand

Minimal

One line at the end of the body that prints the theme scripts and the three core scripts.

<?= theme_js() ?>
</body>

Common: closing the page

Footer, then scripts, then the closing tags; do not reshuffle the order.

</main>

<?= theme_footer() ?>
<?= theme_js() ?>
</body>
</html>

Advanced: a page script after the theme scripts

Page scripts go after the theme scripts so they can rely on what the core has prepared; the path is relative to the pack assets directory.

<?= theme_footer() ?>
<?= theme_js() ?>
<script src="<?= e(theme_asset('js/landing.js')) ?>" defer></script>
</body>
</html>

4. What it does / when to use it

Call it once at the very bottom of every page template, just before the closing body tag. Besides the pack scripts it also emits three core scripts: the code highlighter, the form token upgrade that swaps the site-wide token for the session token on cached pages, and the visit beacon, which is attached only when statistics are enabled and the page type is neither empty nor 404. Do not call it from component or AJAX fragments, and never put it in the head element.

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
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: Call it once at the very bottom of every page template, just before the closing body tag

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)

  1. Write &lt;?= theme_js() ?&gt; as the last statement of the template and close the body and html tags right after it, so every script that touches the DOM finds its elements in place.
  2. Keep the tail order fixed: page content, then theme_footer(), then theme_js(). The scripts bind to footer elements such as the back-to-top button, the QR popup and the mobile drawer, and reversing the order leaves them unbound.
  3. Delete hand-written script tags pointing at theme.js, along with any highlighter or analytics script you added yourself. The hand-written tag misses the token upgrade and the beacon, and a second analytics script double-counts visits.
  4. Put page-specific scripts after theme_js() and load them with &lt;?= e(theme_asset('js/landing.js')) ?&gt; so they can rely on what the core scripts have already set up.
  5. Self-check the rendered source: one theme script block before the closing body tag, and no visit beacon on a 404 page, which would otherwise fill the popular list with URLs crawlers guessed at.

7. Common pitfalls

  • Putting the call in the head element: the scripts block parsing and run before the DOM exists, so every binding fails and clicks do nothing, while the first paint gets slower as well.
  • Replacing the call with a hand-written script tag for theme.js: the code highlighter, the form token upgrade and the visit beacon are all lost. On a page-cached site forms then submit with the site-wide token and visitors get 419 errors, while your own environment looks perfectly fine because the cache is off.
  • Calling it twice: the pack scripts and the beacon load twice, so one visit is counted as two and the popular list drifts away from reality.
  • Writing it after the closing body and html tags, or outputting content after those tags: whatever sits outside the document is discarded by the browser.
  • Loading the highlight script or an analytics snippet again by hand: two highlighters run over the same code blocks and every visit is reported twice.

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>).

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

Page templates 19 files / 19 calls

  • templates/_shared/404.php ×1 lines 42
  • templates/_shared/detail.php ×1 lines 111
  • templates/_shared/feedback.php ×1 lines 70
  • templates/_shared/home.php ×1 lines 63
  • templates/_shared/layout.php ×1 lines 132
  • templates/_shared/list.php ×1 lines 166
  • templates/_shared/maintenance.php ×1 lines 28
  • templates/_shared/member.php ×1 lines 278

Template packs 2 files / 2 calls

  • templates/official/detail_pkg.php ×1 lines 50
  • templates/official/home.php ×1 lines 48

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.

Common combinations (generated from your real templates)

  1. The page template hosting this tag is 404
  • templates/_shared/404.php

11. Previous / next In group order; this is tag 53 of 56.

click the title to collapse / expand
Send an Enquiry