Skip to main content

Working with Variables in PageWorkers Templates

Updated over 5 months ago

📘 This article explains how to define template variables when optimizing meta tags or HTML elements with PageWorkers. PageWorkers is part of Botify's Activation Suite, available as an option with all Botify plans.

Overview

Variables allow you to define an object in your template that extracts a value from your pages according to your defined rules. For example, you can create a "product type" variable that pulls the individual product types from all your product pages. Template variables are saved with each optimization for quick access to reuse variables.

Creating Template Variables

Create variables while defining a template for your optimization on Step 2 of the PageWorkers wizard.

To create a template variable:

  1. Click the Create New Variable link to define a variable to be used in the template.

    pw_create_var_link.png

  2. In the Create New Extracted Variable dialog, provide a name to identify the variable (e.g., “product”). PageWorkers will add the basic syntax for variables around the name ##{{variable name}}.

    pw_variable_define_product.png

  3. If you chose to identify specific URLs in Step 1 of the wizard, choose one of the following methods to provide the new value. If you chose to identify pages to optimize by scope, then proceed to the Extracting Variable Values section.

Identifying Variable Values by URL

This section only displays if you chose to define pages to optimize by specific URLs in Step 1 of the wizard.

pw_extract_variable_url.png

When defining variable values by URL, you select the type of variable from the dropdown list on this page and will define the individual values for each URL to optimize on the next step of the wizard.

Variable types

  • String: The variable is text (e.g., "sneakers").

  • Integer: The variable is a whole number (e.g., 20).

  • Float: The variable is a floating point number (e.g., 5.25).

  • Boolean: The variable is binary (i.e., true/false).

Extracting Variable Values

Variable values are extracted from your pages using the extraction rules you define. A CSS Selector and strategy tells PageWorkers where to extract the value from your page.

pw_extractfrompage.png

To define an extraction rule:

  1. Identify the page URL where you want to test your extraction rules. If you identified a Preview URL when configuring the template, this field will already be populated, but you can change it here.

  2. Identify and test the CSS Selector and extraction strategy outlined in the Using CSS Selectors in PageWorkers article.

  3. If your selected strategy is "Attribute", identify the attribute name in the text box below the Strategy list.

Defining Execution Conditions

Because many websites rely on JavaScript to add dynamic content to their pages, you may want to identify conditions to be met before PageWorkers executes an optimization. This ensures all content is available when the page is initially rendered and all important content appears immediately. For example, you may want to wait for reviews to be added by a third-party tool or for a product's stock information to be confirmed by an API before the PageWorkers optimization executes. When conditions are not required, PageWorkers may execute optimizations before the required content is available on the page.

To identify conditions to be met:

  1. In the “Require conditions” section, slide the Enable requirement toggle to the right.

  2. Select a condition and value to match. PageWorkers will only execute the optimization when the defined condition is met.

👉 When you require conditions, the variable is identified as required.

Managing Template Variables

You can do the following with defined variables:

Reusing Variables

You can reuse variables within the same optimization. To reuse a template variable, simply click the variable name when defining your template. The variable will be added to the template in the location where you selected the variable.

pw_selectvariable.png

Editing and Deleting Variables

You can edit some variable fields or permanently delete a variable.

To edit or delete a template variable:

  1. When defining the template, click the pencil icon next to the variable name.

    pw_editvariable.png

  2. In the Edit Extract Variable dialog, make the desired changes, and then click the Save button; or

  3. Click the Delete button. After you delete, there is no confirmation message; the variable is immediately deleted.

    pw_editdel_variable.png


    If a field is disabled in the Edit dialog, delete the variable and replace it with a new variable.


Read next:

Did this answer your question?