Simulation Development

Strings

Strings are used to localize content. Content may be text, images or anything that pertains to localizing the question. Strings are defined using the following syntax ${STRING_PATH}.

Strings are pre-parsed. Before the HTML is added to DOM:

  1. String files are loaded.
  2. Slides are loaded.
  3. Hammer looks for and replaces the string tags with the string definitions.
  4. Hammer then adds the content to the display.

This means you could add practically anything you want into a string tag, but if you need to add complex HTML, you should instead use a mixin.

timer Exercise: Consuming strings

Though there are several string examples as a reference we are only going to look at out to create and consume a simple string.

Launch in your browser http://localhost:8080/sandbox/#/tutorials/strings/strings_start. It should open a page with "Custom Events Tutorial" displayed.

Open sandbox/slides/tutorials/strings/strings_start.html in seed-exam in your editor.

By default, strings files are located in the strings directory. This can be changed in sandbox/config.json.

Loading a string file

In your slide to use a string file, it must be loaded. To load a string file add the following line in h:virtual

<h:strings url="strings/global" />

The url is relative to sandbox/index.html. If you open sandbox/strings/global.xml, you will notice the root tag is defined as:

<strings xmlns="http://certiport.com/hammer/sdk/strings"></strings>

Hammer uses this information to know this file represents a strings XML file. The xmlns is required by Hammer. It is not declared will throw an error if it is missing.

Note: You can declare any number of h:strings in order to separate strings by structure, question, tasks, whatever works for you.

Defining a string tag

Below h:virtual, add the following line:

<div>${hello}</div>

In your browser, refresh your page. You should now see "Hello, world!" appear on the page.

Be sure to check out the detailed set of examples for using strings in your exam.