In the world of business, companies and organizations often create and distribute documents created from templates possessing a design esthetic that reflects the company’s brand identity. Template-based publishing enables staff to produce quality documentation in a timely and efficient manner. An essential element of template design is in the use of text placeholders that are replaced with custom data when the template is exported.
To enable template publishing, Pages includes scripting support for quickly locating and replacing text placeholders within a document. This support is exposed through the placeholder text class.
The Placeholder Text Class
placeholder text n : A contiguous range of text, identified as a selectable entity, that can be replaced by the user or a script.
elements
contained by documents, rich text, and paragraphs.
properties
tag (rich text ) r/o: A user-supplied text string that can identify a specific placeholder to a script. NOTE: if no tag is assigned to the placeholder, its text will be used as its tag.
An instance of the placeholder text class is a temporary entity in that once its contents have been replaced, it ceases to exist. Since text placeholders have no contents property, their text can be changed through simple use of the set verb.
NOTE: Text placeholders used within tables or charts are not “visible” to scripts.
Script Examples
This example script will create and populate the text and image for a new Tab Flyer document. It uses the tag property of the placeholder text object to prompt the user to supply the replacement text for each of the placeholders. Once the placeholders are replaced, the script prompts the user for the replacement image file.