Welcome to Genhike Sports

Sidebar Widget

← Back to the tag reference

Hand-written Includes in-depth notes

Sidebar Widget widget Used inside components 6 host files / 6 calls

Renders the sidebar widgets configured in the admin, such as Popular Articles or Contact, and accepts an optional widget name.

widget($name, array $config = [])

Pages Site-wide (system)

Used in
Site-wide (system)
Defined in
core/tpl_functions.php:387
Core method
Tpl::widget()
How do I read these repository paths?

All paths are relative to the site root. Open core/tpl_functions.php at line 387 to see the definition of widget(). 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
Required; renders the widget-NAME component, and unknown names render nothing.
Handed to that component as $component_config; no defaults are filled in.
Generated code

Now generating: widget

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.

2. Full parameter table 2 parameters, one per row; scroll sideways on narrow screens.

click the title to collapse / expand
Parameter Type Default Description
name string required / as needed Required; renders the widget-NAME component, and unknown names render nothing.
config array [] Handed to that component as $component_config; no defaults are filled in.

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

click the title to collapse / expand

Minimal

Renders components/widget-contact.php; when that file does not exist this line outputs nothing at all.

<?= widget('contact') ?>

Common: the component file plus the template call

Defaults live in the component; the template passes only the overrides.

<?php /* templates/_shared/components/widget-contact.php */ ?>
<?php
$cfg   = isset($component_config) && is_array($component_config) ? $component_config : [];
$title = isset($cfg['title']) && $cfg['title'] !== '' ? (string)$cfg['title'] : 'Contact us';
$phone = isset($cfg['phone']) ? trim((string)$cfg['phone']) : '';
?>
<section class="ry-side-card">
    <h2 class="ry-side-card__title"><?= e($title) ?></h2>
    <?php if ($phone !== ''): ?>
        <p class="ry-side-card__line"><?= e($phone) ?></p>
    <?php endif; ?>
</section>

<?php /* call it from any template */ ?>
<?= widget('contact', ['title' => 'Sales enquiry', 'phone' => '400-000-0000']) ?>

Advanced: one component in two places with different config

Differentiate the two placements through the config array instead of copying the file.

<aside class="ry-side">
    <?= widget('contact', ['title' => 'Sales enquiry', 'phone' => '400-000-0000']) ?>
    <?= widget('contact', ['title' => 'After-sales support', 'phone' => '400-000-0001']) ?>
</aside>

4. What it does / when to use it

Use it to call a reusable sidebar part that lives in its own component file, so one contact card or popular list can be dropped into several templates with a single line and overridden per template pack. It resolves components/widget-{name}.php, which makes it an extension point rather than a factory widget set: no widget component ships in the box, and a name without a matching file renders nothing. It is not a data tag, so keep content queries in the query tags and let this one carry markup.

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: Use it to call a reusable sidebar part that lives in its own component file, so one contact card or popular list can be

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. Pick a name that uses only letters, digits, hyphens and underscores, for example contact.
  2. Create templates/{pack}/components/widget-contact.php, or templates/_shared/components/widget-contact.php when every pack should share it, and write ordinary component markup inside.
  3. Read $component_config inside the file for anything the caller passes, and keep default values in the component so the template only supplies differences.
  4. Call it from the template with <?= widget('contact') ?>, which renders that file together with the current page context.
  5. Pass options as the second argument, for example a title and a phone number, so two placements of the same component differ without duplicating the file.

7. Common pitfalls

  • An empty name does not mean render every widget. The core concatenates widget- plus the name and looks for that file, so an empty name looks for widget-.php, which normally does not exist and renders nothing; only debug mode leaves an HTML comment behind. Call the tag once per widget instead.
  • When the component file is missing the tag fails silently and the block simply disappears from the page, which is the most common reason for a call that produces nothing. Confirm the file exists and that the name matches the call character for character.
  • Characters outside letters, digits, hyphens and underscores are stripped from the name before the lookup, so a name containing a space, a dot or a non ASCII character will not match the file you created. Avoid them and never put a file extension in the name.
  • Component resolution prefers the current template pack. A same named file inside the active pack shadows the shared one, which explains a change that appears to have no effect. Check which pack is active first.
  • The return value is HTML. Print it directly and do not escape it, or the visitor sees the tag source.

Note from the reference table No widget-*.php component ships with the core or the template packs, so on a stock install widget('contact') prints nothing; the sidebar is rendered by the sidebar.php component, and name has no default either.

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 outputs a whole page region (this site header / footer / a full layout section, or it decides what to render from the current page data). Inside this small box it would just splice another page skeleton into this one: you would not see its real effect, and it would wreck this page. Copy it into your template instead.

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 6 files / 6 calls 89% of tag calls live in components

  • templates/_shared/components/contact-split.php ×1 lines 570
  • templates/_shared/components/footer-newsletter.php ×1 lines 445
  • templates/_shared/components/hero-split-form.php ×1 lines 546
  • templates/_shared/components/inquiry-form-card.php ×1 lines 447
  • templates/_shared/components/inquiry-form-minimal.php ×1 lines 356
  • templates/_shared/components/inquiry-form.php ×1 lines 153

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.

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

click the title to collapse / expand
Send an Enquiry