Template class

The Template class gives access to templates in Reporter. More...

The REPORTER JavaScript API provides many class constants, properties and methods. For Arup to be able to extend and enhance the API in the future any constant, property or method names beginning with a lowercase or uppercase letter are reserved.
If you need to add your own properties or methods to one of the existing classes then to avoid any potential future conflict you should ensure that the name begins with either an underscore (_) or a dollar sign ($) or the name is prefixed with your own unique identifier.
For example if company 'ABC' need to add a property called 'example' then to avoid any potential future conflict use one of:

Class functions

Member functions

Template properties

Name Type Description
filename (read only) string Filename (without path) of the Template.
generating (read only) logical true if the entire template is currently being generated
name (read only) string This property is deprecated in version 15.0. It is only provided to keep old scripts working. We strongly advise against using it in new scripts. Support may be removed in future versions.
Name of the Template. This property has been preserved for compatability with older scripts. It either contains the absolute path and filename, or just the filename, depending on how the Template was opened. Please use the filename and path properties for consistent results.  [deprecated]
pages (read only) integer Number of Pages in template
path (read only) string Absolute path (without filename) of the Template. If the Template is new and has not yet been saved, this property will be empty.
readonly (read only) logical true if the template is read-only
variables array This property is deprecated in version 12.0. It is only provided to keep old scripts working. We strongly advise against using it in new scripts. Support may be removed in future versions.
Array of Variable objects for this template. Please use Variable.GetAll() and Variable.GetFromName() instead.  [deprecated]
view constant Current view type (presentation or design view) for this Template. Can be: Reporter.VIEW_DESIGN or Reporter.VIEW_PRESENTATION.

Detailed Description

The Template class allows you to access the templates that Reporter currently has open.
Note that if you want to get a list of the current templates in Reporter you should see the templates array in the reporter object.
The currently active template is stored in the currentTemplate property of the reporter object.

Constructor

new Template(filename (optional)[string])

Description

Create a new Template. The filename argument is optional. If present it is a file to open

Arguments

  • filename (optional) (string)

    Name of template file to open

    Returns

    Template object

    Return type

    Template

    Example

    To create a new blank Template object

    var template = new Template();

    Details of functions

    Close()

    Description

    Close a template.
    Note that if you call this function for a Template object, the Template data will be deleted, so you should not try to use it afterwards!.

    Arguments

    No arguments

    Returns

    no return value

    Example

    To close template data:

    data.Close();


    DeletePage(index[integer])

    Description

    Deletes a page from a template.

    Arguments

  • index (integer)

    The index of the page that you want to delete. Note that indices start at 0.

    Returns

    No return value

    Example

    To delete the first page of template t:

    t.DeletePage(0);


    DeleteTemporaryVariables()

    Description

    Deletes any temporary variables from a template.

    Arguments

    No arguments

    Returns

    No return value

    Example

    To delete all the temporary variables from template t:

    t.DeleteTemporaryVariables();


    EditVariables(title (optional)[string], message (optional)[string], update (optional)[boolean], variables (optional)[array], columns (optional)[constant], alphabetical (optional)[boolean])

    Description

    Start a dialog to edit the template variables

    Arguments

  • title (optional) (string)

    Title for dialog. If omitted, null or an empty string is given then the default title will be used.

  • message (optional) (string)

    Message to show in dialog. If omitted, null or an empty string is given then the default message will be used.

  • update (optional) (boolean)

    Whether the variables in the template will be updated with the new values if OK is pressed. Setting this to be false allows you to check variable values before updating them from a script. If omitted the default is true

  • variables (optional) (array)

    A list of variables to show in the dialog. If omitted, null or an empty array, all variables will be shown

  • columns (optional) (constant)

    Columns to show in the dialog (as well as the variable value column). Can be a bitwise OR of Variable.NAME, Variable.TYPE, Variable.DESCRIPTION, Variable.FORMAT, Variable.PRECISION and Variable.TEMPORARY. If omitted columns will be shown for name and description

  • alphabetical (optional) (boolean)

    Whether to sort variables in the table by alphabetical order. If false, variables are listed in the order they are passed in the optional variables argument. If no variables are passed to the function, all template variables will be shown in alphabetical order. If omitted, the default value is true.

    Returns

    Object containing the variable names and values or null if cancel was pressed.

    Return type

    Object

    Example

    To edit all of the variables in template:

    var variables = template.EditVariables();

    To edit variables TEST and EXAMPLE in template giving a title and a message, returning the edited values but not updating them in the template:

    var variables = template.EditVariables("Edit variables",
    "Type in the values", false, ["TEST", "EXAMPLE");


    ExpandVariablesInString(string[string])

    Description

    Replaces any variables in a string with their current values

    Arguments

  • string (string)

    The string you want to expand variables in.

    Returns

    String (string) with variables expanded. If a variable in a string does not exist it is replaced by a blank.

    Return type

    String

    Example

    If the variable FRED in template contains the value "test", then the following

    var value
    = template.ExpandVariablesInString("This is a %FRED%");

    will return "This is a test" in variable value.


    Generate()

    Description

    Generate a template

    Arguments

    No arguments

    Returns

    no return value

    Example

    To generate template data:

    data.Generate();


    GetAll() [static]

    Description

    Get all of the open templates

    Arguments

    No arguments

    Returns

    array of Template objects or null if no open templates

    Return type

    Array

    Example

    To get all of the templates open in REPORTER:

    var templates = Template.GetAll();


    GetAllPages()

    Description

    Gets all of the pages from a template.

    Arguments

    No arguments

    Returns

    Array of Page objects

    Return type

    Array

    Example

    To get all of the pages from template t:

    var pages = t.GetAllPages();


    GetCurrent() [static]

    Description

    Get the currently active template

    Arguments

    No arguments

    Returns

    Template object or null if no active template

    Return type

    Template

    Example

    To get the current template open in REPORTER:

    var current_template = Template.GetCurrent();


    GetMaster()

    Description

    Get the master page from a template.

    Arguments

    No arguments

    Returns

    Page object

    Return type

    Page

    Example

    To get the master page of template t:

    var m = t.GetMaster();


    GetPage(index[integer])

    Description

    Get a page from a template.

    Arguments

  • index (integer)

    The index of the page that you want to get. Note that indices start at 0.

    Returns

    Page object

    Return type

    Page

    Example

    To get the first page of template t:

    var p = t.GetPage(0);


    GetVariableDescription(name[string])

    Description

    Get the description for a variable

    Arguments

  • name (string)

    Variable name you want to get description for.

    Returns

    Variable description (string) or null if variable does not exist

    Return type

    String

    Example

    To get description for variable FRED in template:

    var description = template.GetVariableDescription("FRED");


    GetVariableValue(name[string])

    Description

    Get the value for a variable

    Arguments

  • name (string)

    Variable name you want to get value for.

    Returns

    Variable value (string) or null if variable does not exist

    Return type

    String

    Example

    To get value for variable FRED in template:

    var value = template.GetVariableValue("FRED");


    Html(filename[string])

    Description

    Save a template as HTML

    Arguments

  • filename (string)

    Filename you want to save.

    Returns

    no return value

    Example

    To save template data as file /data/test/template.html:

    data.Html("/data/test/template.html");


    Pdf(filename[string])

    Description

    Save a template as Adobe Acrobat PDF

    Arguments

  • filename (string)

    Filename you want to save.

    Returns

    no return value

    Example

    To save template data as file /data/test/template.pdf:

    data.Pdf("/data/test/template.pdf");


    Ppt(filename[string])   [deprecated]

    This function is deprecated in version 18.0. It is only provided to keep old scripts working. We strongly advise against using it in new scripts. Support may be removed in future versions.

    Description

    Save a template as PowerPoint. This function is deprecated. Use Template.Pptx instead.

    Arguments

  • filename (string)

    Filename you want to save.

    Returns

    no return value

    Example

    To save template data as file /data/test/template.pptx:

    data.Ppt("/data/test/template.pptx");


    Pptx(filename[string])

    Description

    Save a template as PowerPoint

    Arguments

  • filename (string)

    Filename you want to save.

    Returns

    no return value

    Example

    To save template data as file /data/test/template.pptx:

    data.Pptx("/data/test/template.pptx");


    Print(printer[string])

    Description

    Print template on a printer

    Arguments

  • printer (string)

    Printer you want to print to.

    Returns

    no return value

    Example

    To print template data on printer myprinter:

    data.Print("myprinter");


    Save()

    Description

    Save a template

    Arguments

    No arguments

    Returns

    no return value

    Example

    To save template data:

    data.Save();


    SaveAs(filename[string], readonly (optional)[boolean])

    Description

    Save a template/report with a new name

    Arguments

  • filename (string)

    Filename you want to save. Note if you use the .orr extension the template will be saved as a report if generated.

  • readonly (optional) (boolean)

    If saved template/report will be readonly or not.

    Returns

    no return value

    Example

    To save template data as file /data/test/template.opt:

    data.SaveAs("/data/test/template.opt");


    Update()

    Description

    Update/redraw a template

    Arguments

    No arguments

    Returns

    no return value

    Example

    To update template data:

    data.Update();