Click here to ask a question or provide feedback on this topic Bookmark this topic Print this topic     Next

Using variables

IntraWeb Studio supports variables in documents which get automatically expanded. Using variables is a powerful technology to avoid redundant information in your documents.

Defining Variables

To define a new variable select "Document - New" and choose "Variable":

Then just enter the variable's text.

Note: If you use the integrated HTML editor to edit your variables, then it might add a <html><body></body><html> container arround the variables text. This does not matter, as IWS will use only the text inside the body tag. If there is no body tag, then the whole text will be used.

Syntax

Variable names are case insensitive. Variables are inserted into the document using a special tag.

Project variables

To reference variables in the same project, use this syntax:

{%Project.VariableName%}

Cross project variables

To reference variables of other projects on the same repository, use this syntax:

{%Project[ProjectName].VariableName%}

Note: Currently only variables in the root directory of other projects can be accessed using the alternative syntax.

Document Variables

Document variables are variables which are tied to one specific document. If you have a document called "Index", and if it has a reference to a variable "test" {%Project.Test%}, then IWS will look for a variable called "Index$Test" first (in the same folder where "Index" is located). This is part of IWS' powerful "Variable Overriding" feature, see below.

Overriding Variables

Suppose you have a document called "Index", and it references {%Project.Test%}, then IWS will:

  1. first check for a variable called "Index$Test" in the current folder, and uses that if it exists
  2. else IWS will look for a variable called "Test" in the current folder, and uses that if found
  3. else IWS will go to the parent folder and look for "Test" there, until it reaches the root (including root)
  4. if still nothing can be found, then the variable will be removed from the output.

Variable Types

Three different types of variables are supported:

Variable Features

Nested variables

Nesting variables allows you to use variables in other variables.

Variables with Parameters

Using Parameters variables behave pretty much like functions or macros. See the "Variables with Parameters" example.

Notes: Variables get expanded in Managed Documents only. They can not be used in simple files like text files etc.

Examples

Example 1

Using Variables in templates:

<HTML> 
    <HEAD> 
      <TITLE>{%title%}</TITLE> 
    </HEAD> 
    <BODY> 
      {%body%} 
      <HR> 
      Author: {%Project.MyName%} 
      Last update: {%YEAR%}-{%MONTH%}-{%DAY%} 
    </BODY> 
</HTML>

Example 2

Using nested Variables:

Set a Variable "Company" = "Pet Company Ltd."

Set a Variable "CopyrightNote" = "Copyright {%Project.Company%} (c) {25.06.2005}"

Using {%Project.Company%} and {%Project.CopyrightNote%} in your documents will keep both strings in sync, just by editing the variables.

Example 3

Variables with Parameters:

When referencing a variable in a document, you can pass one or more parameters. This can be used to define virtual functions.

Suppose you have a couple of images, each in a small and a big version. On the index document you want to display all of them as small, clickable thumb nails. With IWS you can just add this to your document:

<BODY> 
{%PROJECT.POPUP??IMAGENAME=picture1.jpg%}<BR> 
{%PROJECT.POPUP??IMAGENAME=picture2.jpg%}<BR> 
{%PROJECT.POPUP??IMAGENAME=picture3.jpg%}<BR> 
{%PROJECT.POPUP??IMAGENAME=picture4.jpg%}<BR> 
</BODY> 

You need to define a Variable "POPUP" like this:

<A href="images_highres/{%IMAGENAME%}" target="_Blank">
<IMG src="images_lores/{%IMAGENAME%}"></A> 

IWS will resolve the "local" variable "IMAGENAME" by pulling its value from the IMAGENAME=value definition in the document above.

Multiple Parameters are separated via two question marks: ??

{%PROJECT.VariableName??ParamName1=Value1??ParamName2=Value2%}

If one of the values should contain two question marks then escape them with a backslash: \??

{%PROJECT.VariableName??Param1=Hello World!??param2=yes/no%}

This will assign "Hello World!" to Param1.



Feedback? Bookmark this topic     Next

We use the ABCpdf .NET PDF component for HTML to PDF conversion...