Using Templater Data in Expressions
In Templater 2.8.0 and later, you can use data in expressions by referencing the Source Text property of a dynamic text layer or any data parameter from Templater's JSON footage layer. Because all Templater data are interpreted as Strings, it is useful to cast them as other data types within your expression code. For example, you might want to cast Templater's String data as Integer, Float, Array, Boolean, or JSON Object for processing by your code.
In expression code, referencing JSON footage is a more user-friendly and intuitive process, but it leverages a feature in After Effects that may require manual interaction during batch processes. As of After Effects 15.1.1, we recommend referencing dynamic text layers' Source Text property in expression code as a more stable solution.
- Map data to a text layer according to instructions in Mapping Templater Data to Layers.
- In After Effects, reveal the text layer's Source Text property.
- In another layer, use a property's pickwhip to reference the dynamic layer's Source Text property within the expression code.
- If necessary, add expression code that casts the referenced Source Text value as a Float, Integer, or Array. If your expression code requires a String, you can reference it without casting.
For example:
- Use
parseInt()
to cast a String as an Integer. - Use
parseFloat()
to cast a String as a Float. - Use
parseNumber()
to cast a String as either an Integer or a Float. This method determines which type is needed. - Use
eval()
to cast a String as an Object or Array.
- Finish entering expression code.
WARNING Mapping data to expressions is an experimental feature, and is supported as such until a future release of After Effects. As of After Effects version 15.1.1, a modal dialog requires user interaction when the source of an imported JSON footage item changes structure. This dialog notice can interfere with Templater's batch processes. Track the status of this bug in Adobe's Uservoice forums.
WARNING Previews using this experimental feature do not automatically update within After Effects due to a bug with ExtendScript where AE does not detect the file changes to reload the file. Rendering should still work with the correct data imported. Track the status of this bug in Adobe's Uservoice forums.
- In the Templater Preferences dialog, in the Data Source section, enable the Import Templater data as JSON footage preference. When this setting is enabled, Templater automatically creates a JSON file with data from a single job and imports it into the project.
- Link your data source to your After Effects project. See Data Source for more information.
- In the main Templater panel, in the Transport section, use the Transport control buttons to advance the preview. A file titled templater-data.json appears in the project panel. For each processed job, Templater overwrites the templater-data.json file with that job's data.
NOTE The templater-data.json file will only ever have one object in the file's root JSON array. Also, all property values in the templater-data.json file are always Strings data due to how After Effects handles changes in imported JSON footage items.
- Click and drag the templater-data.json file to the target composition's timeline to add it as a layer within the composition. Alternatively, you can add it to a composition nested within your target composition.
- If you plan to use Templater's replication feature, apply the Templater Settings effect to the JSON footage layer. Go to Effect > Dataclay > Templater Settings.
- Reveal the JSON layer's Data property group as well as the dataOutline 0 property group to reveal the property keys in the templater-data.json file. These correspond to the column names for spreadsheets or property keys in your JSON feed.
- Edit the expression for your chosen layer property. Use the field's pickwhip to reference the specific parameter from the dataOutline 0 group under the templater-data.json file.
- If necessary, add expression code that casts the String value as a Float, Integer, or Array. If your expression code requires a String data type, you can directly reference it without casting it.
For example:
- Use
parseInt()
to cast a String as an Integer. - Use
parseFloat()
to cast a String as a Float. - Use
parseNumber()
to cast a String as either an Integer or a Float. This method determines which type is needed. - Use
eval()
to cast a String as a JSON object or an array.
- Finish entering the property's expression code.