| 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 VariablesTo 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. SyntaxVariable names are case insensitive. Variables are inserted into the document using a special tag. Project variablesTo reference variables in the same project, use this syntax: {%Project.VariableName%} Cross project variablesTo 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 VariablesDocument 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 VariablesSuppose you have a document called "Index", and it references {%Project.Test%}, then IWS will:
Variable TypesThree different types of variables are supported:
Variable FeaturesNested variablesNesting variables allows you to use variables in other variables. Variables with ParametersUsing 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. ExamplesExample 1Using Variables in templates: <HTML>
<HEAD>
<TITLE>{%title%}</TITLE>
</HEAD>
<BODY>
{%body%}
<HR>
Author: {%Project.MyName%}
Last update: {%YEAR%}-{%MONTH%}-{%DAY%}
</BODY>
</HTML>
Example 2Using 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 3Variables 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. |
We
use the ABCpdf .NET PDF component for HTML to PDF conversion...