CommandBase Class

Base class for all commands that exist in BasisCore and present common functionalities used in rendering engine. For list of commands, see Built-in Commands

Note

All attributes declared in this class, accessible in child class, but all of them isn’t usable in all commands. For example name attribute in DbSource is required, but in Print Command is optional.

Structure of CommandBase
1
2
3
<basis core="" id="" name="" if="" run="" >
 ...
</basis>

or

Structure of void CommandBase
1
<basis core="" id="" name="" if="" run="" />

New in version 3.0: Added id, if, run properties.

Attributes

core string required

Determine type of command like Print Command or List Command. For example see Create Simple Command.

id string optional

Use this property for set unique identifier for command. The id use only in debugging or some advanced case. Default value is null. For example see Create Simple Command.

name string optional [##-notation

Use this property for set name for command. This attribute for some commands like Source Commands is required. Default value is null. For example see Create Simple Command.

if string optional [##-notation expression

The boolean expression to determine that command can be execute or not. Default value is true. For example see Simple Conditional Execution ,and Complex Conditional Execution.

run RunType optional [##-notation

Determine side of executing command. Default value is AtServer. For more information see RunType Enum. For example see Create Simple Command.

Note

For see more Information about [##-notation, see [## Notation

Example

For learn how to create and run BasisCore Code, see Get start.

Create Simple Command

In this example we create simple Print Command command for learn how to use command in document body.

Note

For more information about print command, see Print Command.

First add basis tag to document:

1
2
<basis>
</basis>

Then add core attribute with some value. In this example we go to create a Print Command command:

1
2
<basis core="print">
</basis>

In next step, add meaningful name and id.

1
2
<basis core="print" id="print-cmd-test" name="test-print">
</basis>

As mentioned previously, This two properties for some commands like Print Command is optional and can be omitted. To run command in client browser set run attribute like this:

1
2
<basis core="print" id="print-cmd-test" name="test-print" run="atclient">
</basis>

At last,add Print Command command specific elements like face tag and datamembername attribute. complete command is:

1
2
3
4
5
<basis core="print" id="print-cmd-test" name="test-print" run="atclient" datamembername="db.test-data" >
   <face>
      <h1>@title</h1>
   </face>
</basis>

Simple Conditional Execution

In this example we go to display if attribute functionality by using expression.

Note

For simplicity, we remove unnecessary part of command in this example.

Suppose we have a print command and want to add conditional rendering to it. In our example client request query string contain do-print key with either true or false value. Value of do-print determine that print command must be execute or not.

1
2
3
<basis core="print" if="[##cms.query.do-print##]" >
   [...]
</basis>

In above example, in query string contain somethings like do-print=true, value of if set to true and this expression interpreted as true boolean value. So if evaluation is true and print command executed. But for di-print=false value of query string, evaluation is false and command not executed.

Note

Any type of boolean expression supported in if. for example, all below expression is valid:

  • 1+1 > 2

  • (12/3) <= 5

  • [##cms.form.agree##] = true

  • ‘[##cms.form.pass]’ = ‘[##cms.form.confirm-pass##]’

It Also possible to use AND, OR , NOT and () for create complicated boolean expression:

  • [##cms.form.agree##] = true and ‘[##cms.form.pass]’ = ‘[##cms.form.confirm-pass##]’

For more Information See expression

Complex Conditional Execution

In this example we go to use complex expression for set if attribute to present custom business in conditional rendering.

Note

For simplicity, we remove unnecessary part of command in this example.

Our simple print command that use in this example is:

1
2
3
4
5
<basis core="print" datamembername="db.test-data" >
   <face>
      <h1>@title</h1>
   </face>
</basis>

Suppose client request query string contain A, B and C key. Value for this keys is 2, 3 , 6 respectively. Now set [##cms.query.A##]*[##cms.query.b##] = [##cms.query.C##] expression for if attribute:

1
2
3
<basis core="print" if="[##cms.query.A##]*[##cms.query.b##] = [##cms.query.C##]">
   [...]
</basis>

In generating result process print command execute because after replace process in if attribute , new expression is 2*3 = 6 that is true value after evaluation.

More True Example:

* [##cms.query.A##] = [##cms.query.C##]/[##cms.query.b##]
* ([##cms.query.A##] = 2) and ([##cms.query.b##] = 3)
* ([##cms.query.A##] = 2) OR ([##cms.query.b##] = 7)
* ([##cms.query.A##] = 2) and ([##cms.query.b##] = 3 OR [##cms.query.b##] = 5)
* not([##cms.query.A##] = 1)
* NOT([##cms.query.b##] = 5 OR [##cms.query.c##] = 5)

More false Example:

* [##cms.query.A##] = 6
* ([##cms.query.A##] = 2) and ([##cms.query.b##] = 6)
* ([##cms.query.A##] = 3) and ([##cms.query.b##] = 3 OR [##cms.query.c##] = 6)
* not ([##cms.query.A##] = 2)