1. AAWP
  2. Documentation
  3. Tips & Tricks
  4. Template Variables

With template variables you can pass variables directly via shortcode and access them inside the template files.

Passing variables

Template variables must be prefixed with tpl_. The name behind it can be chosen freely.

[amazon box="ASIN" tpl_var1="test" tpl_var2="text1,text2,text3" /]

Comma-separated values ​​are converted directly into an Array.

Accessing variables inside the templates

Within the template files, the following functions are available:

Accessing all variables

$variables = $this->get_template_variables();

… returns an Array with all passed values.

Accessing single variable

$variable = $this->get_template_variable( 'var1', 0 );

… returns a certain passed value.

By passing a second parameter to the function, you can define a default value.

Was this article helpful?

Related Articles