Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,090 of 9,090 pages
About the help in other languages
All help pages

Run-once

The run-once function prints its body only the first time it is reached during a request, which keeps markup that several included templates need (a sprite, a dialog, a data block) from appearing twice.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/designers/templates/run-once.md

On this page

Run-once

This page is for designers whose parts may be included several times on a page but need some markup only once.

Contents

  1. Syntax
  2. When to use it
  3. Cautions

Syntax

From lib/eztemplate/classes/eztemplateblockfunction.php:

{run-once}
<p>This appears only one time</p>
{/run-once}

The first time the block is reached in a request, its body is printed; every later time, it is skipped. The key is the block's place in the template, so two different {run-once} blocks are independent.

When to use it

A gallery part that is included for every gallery on a page needs one shared dialog for the large image view:

{* design/mytheme/templates/parts/gallery.tpl *}
{run-once}
<dialog class="lightbox" id="lightbox">
    <button type="button" class="lightbox-close">{'Close'|i18n( 'design/mytheme' )}</button>
    <img alt="">
</dialog>
{ezscript_require( array( 'lightbox.js' ) )}
{/run-once}
<ul class="gallery">...</ul>

For stylesheets and scripts alone, ezcss_require and ezscript_require already avoid duplicates.

Cautions

  • In a view-cached template, "once" means once when the cache was written; the cached HTML then always contains it.
  • Inside a cache-block, the same: the stored output decides.
  • Prefer putting shared markup in the pagelayout when every page needs it.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x