Template::switchCase - jcobban/Genealogy GitHub Wiki
Up: class Template
This is a convenience function that uses the capabilities of class TemplateTag to implement the behavior of a switch/case statement. For example given a portion of a template that looks like:
<span id='case'>
<span data-case='1'>text to display for value 1</span>
<span data-case='2'>text to display for value 2</span>
<span data-case='3'>text to display for value 3</span>
<span data-case='4'>text to display for value 4</span>
</span>
$template->switchCase('case',3)
displays only the contents of <span data‑case='3'>. The template uses the 'data-case' attribute because all browsers that support HTML5 permit the definition of attributes starting with "data-" without issuing a diagnostic. Note that the implementation does not depend upon the tag type. <span> is used only as an example.
The method takes two parameters:
parameter | description |
---|---|
$prefix | the value of the 'id' attribute of the tag which contains all of the alternatives. |
$value | the value of the attribute `data-case' in the sub-tag which encloses the portion of the template to be displayed. The other alternatives are deleted from the Document Object Model (DOM). |