TemplateTag::childNodes - jcobban/Genealogy GitHub Wiki

$tag->childNodes()

Up: class TemplateTag

This method returns the immediate children of the tag as an array of instances of TemplateTag. This can be called as a method, or accessed as a property as it is in JavaScript.

Tables of context specific information can be placed in a template and extracted for use by the server application, particularly for support of internationalization. For example the names of months for a particular language could be stored as follows:

<div id="Months">
  <span></span><!-- index zero -->
  <span>Janvier</span>
  <span>Fevrier</span>
  <span>Mars</span>
  <span>Avril</span>
  <span>Mai</span>
  <span>Juin</span>
  <span>Juillet</span>
  <span>Août</span>
  <span>Septembre</span>
  <span>Octobre</span>
  <span>Novembre</span>
  <span>Decembre</span>
</div>

and loaded into an array to translate month numbers into names by:

$months		= $template['Months'];
$november       = $months[11];      // contains 'Novembre'

Internationalization solutions exploit a table that translates words and phrases from the language of the original implementation into the language of the user. Such a table can be defined in the template file as follows:

<div id="tranTab">
    <span data-key=""></span>
    <span data-key="about">environ</span>
    <span data-key="AD">ap. J.-C.</span>
    <span data-key="adopted">adopté</span>
    <span data-key="after">apres</span>
    <span data-key="an unknown person">une personne inconnue</span>
    <span data-key="and">et</span>
    <span data-key="Apr">Avr</span>
    <span data-key="April">Avril</span>
    ...
    <span data-key="Young">Jeune</span>
</div>

Although the template engine does not care what attribute name you use, the HTML5 specification reserves attribute names that start with "data-" for application use, and ensures that they are accessible to the application. Therefore the attribute data-key is used so that the template remains valid HTML5. This translation table is loaded into the application as follows:

$tranTab	        = $template['tranTab'];
$and                    = $tranTab['and'];        // contains 'et'

Note that a translation table of this sort can be passed to the toString method of an instance of the class LegacyDate, in order to provide the translation required for expressing dates in other languages. Such a translation table can also be passed to the getName method of an instance of Person, which will in turn pass it to the toString method of LegacyDate so that the dates presented as part of the value returned from $person->getName($tranTab), will be expressed in the target language.

Next: $template->parentNode()

⚠️ **GitHub.com Fallback** ⚠️