Run-once
This page is for designers whose parts may be included several times on a page but need some markup only once.
Contents
Syntax
From lib/eztemplate/classes/eztemplateblockfunction.php:
run-once
<p>This appears only one time</p>
/run-onceThe 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.
Related pages
- Cache-block
- Include
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
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.