VTML
Github icondownload
Tutorial
Getting startedHello worldMy first siteAdding a form
Documentation
VariablesLogicPagesFormsChecksPortalsJavascript
Reference
v-withv-ifv-unlessv-for-eachv-portalv-jsonv-yamlv-markdownv-sqlv-nodejsv-dumpv-hint-portv-pagev-exposev-set-cookiev-includeformv-outputv-check-*v-catchv-tryv-set-statusv-redirect
warning

VTML and vtml.org is in alpha and under active development. Use at your own risk

warning

VTML is in alpha. Use at own risk.

<v-with>

Include content block if variable is truthy.

Can also abbreviate long variable paths with the as attribute.

namerequiredtemplated
sourceyesyes
asnono
<v-json target="$dog" >
  {
    "name": "Freddy"
  }
</v-json>

<v-with source=$dog.name as=$name >
  <p>This will display the name : $name </p>
</v-with>

<v-with source=$dog.phone_number >
  <p>This would not display anything</p>
</v-with>

<v-if>

Display the contents only when the condition matches.

By default the contents are displayed when $source is considered truthy.

If multiple check arguments are supplied then all must match.

namerequiredtemplated
eqnoyes
ltnoyes
ltenoyes
gtnoyes
gtenoyes
sourceyesyes
<v-json target=$number >22</v-json>

<v-if $number gt=3 gte=22 lt=100 lte=80 >
  <p>All true!</p>
</v-if>

<v-unless>

Display the contents only when the condition does not match.

Works exactly the same way as v-if but negated.

namerequiredtemplated
eqnoyes
ltnoyes
ltenoyes
gtnoyes
gtenoyes
sourceyesyes
<v-nodejs target=$data >
  return { foo:"Foo" }
</v-nodejs>

<v-unless $data.bar >
  No bar is the data
</v-unless>

<v-for-each>

Repeat the content of the block for each element of source array or varible.

namerequiredtemplated
sourceyesyes
asyesno
keyasyesno
<v-json target=$simpsons >["Marge, "Homer", "Lisa", "Bart", "Maggie"]</v-json>
<ul>
  <v-for-each $simpsons as=$character keyas=$i >
    <li>$i : $character</li>
  </v-for-each>
</ul>

<v-portal>

Define a section of the page that can be requested independently of the rest of the page.

It is useful when you want to be able to refresh part of the client page using ajax.

namerequiredtemplated
pathyesno
<form v-name="create_thingy" >

<v-sql target=$thingys >
  select * from thingys;
</v-sql>

<v-portal path="/thingys" >
  <v-for-each $thingys >
    <p>$thingy.name</p>
  </v-for-each>
</v-portal>

<v-json>

Create a new variable at target from a json body or using the src argument

namerequiredtemplated
targetyesno
srcnono
<v-json target=$inline >
  {
    iam: "some json"
  }
</v-json>

<v-json target=$fromfile src="./some/file.json" />

<v-yaml>

Create a new variable at target from a yaml document specified by the src argument.

Cannot use a body due to confusing indenting.

namerequiredtemplated
targetyesno
srcyesno
<v-yaml target=$data src="./my_data.yml" />

<h3>$data.title</h3>

<v-markdown>

Load in-place a markdown document.

No templating occurs on the markdown document.

You can load markdown either from a src file, a variable, or the element body.

When using the element body make sure that the tag is left-aligned.

namerequiredtemplated
srcnono
sourcenono
<v-markdown>
# Title
```
Some code
```
</v-markdown>

<v-markdown src="./some/markdown.md" />

<v-markdown $a_markdown_var />

<v-sql>

Execute sql query and set a new variable at target

namerequiredtemplated
targetyesno
single-rownono
<v-sql target=$people > select * from people where occupation = 'developer'; </v-sql>

<v-nodejs>

Embed a nodejs function and set target to the return value

If the import attribute is set then the javascript library at that path will be imported and set to the target variable.

namerequiredtemplated
targetyesno
importnono

<v-dump>

Dump the current variable as json inside a pre tag

namerequiredtemplated
sourceyesyes
<v-json target=$data >{ "foo":"Foo", "bar":"Bar" }</v-json>
<v-dump source=$data />

<v-hint-port>

A hint to the VTML engine to listen on this port

namerequiredtemplated
portyesno
<v-hint-port port="1066" />

<v-page>

Define a page within the document.

See the Pages documentation form more details.

namerequiredtemplated
pathyesno
<v-page path="/cats" >
  <p>Cat page!</p>
</v-page>
<v-page path="/dogs" >
  <p>I'm the Dog page</p>
</v-page>

<v-expose>

Expose a file specified at (src) at http (path)

namerequiredtemplated
pathyesno
content-typenono
srcyesno
<v-expose path="/favicon.ico" src="./assets/vtml_icon.png" content-type="image/png" />

<v-set-cookie>

Set a response cookie.

The maximum cookie age will be set to the sum of the max-* attribute values.

namerequiredtemplated
nameyesyes
valueyesyes
max-secondsyesyes
max-minutesyesyes
max-hoursyesyes
max-daysyesyes
<v-set-cookie
    name="session_key"
    value=$session_key
    max-days=365
/>

<v-include>

pre-process

Include an external vtml file. This tag is processed before anything else.

<v-include src="./some/other/file.vtml" />

<form>

Although form is an inbuilt tag we do alter it's behaviour. Defining a form with method="POST" and an v-name attribute will create an action endpoint.

namerequiredtemplated
v-nameyesno
v-ajaxyesno

<v-output>

Specify the output jsonschema of a form API endpoint and the variable to output.

namerequiredtemplated
sourceyesno
<form v-name="create_person" >
  <input name="new_name" required />

  <v-action>
    <v-sql target=$new_person single-row >
      -- Insert a new person and return the new row
      insert into people (name) values ($.body.new_name) returning id, name;
    </v-sql>

    <v-output $new_person >
      {
        "title": "Person",
        "type": "object",
        "properties": {
          "id": { "type":"number" },
          "name": { "type":"string" }
        }
      }
    </v-output>
  </v-action>
</form>

<v-check-*>

Similar to the v-if tags the v-check-* tags will conditionally display a block.

Unlike the x-if tag an error status will be set for the whole page if the condition is not met.

Useful for creating an error-barrier for resources.

namerequiredtemplated
eqnoyes
ltnoyes
ltenoyes
gtnoyes
gtenoyes
sourceyesyes
<v-sql target=$user single-row >
  select * from user where email = $.headers.x-email
</v-sql>

<v-check-authorized source="$user" >
  <p>Some sensitive information here...</p>
</v-check-authorized>

<v-catch>

Rendered when an error has occured.

The special variable $error will be available to display.

The error variable contains:

You don't need to set the error code to the page with <v-set-status>.

<v-catch>
  <p>Error $error.message</p>
</v-catch>

<v-try>

Rendered when no error has occured. Useful when a section may result in an error.

Can be used in conjunction with v-catch to catch errors that may occur within it's contents.

<v-try> <v-sql>Im invalid SQL</v-sql> </v-try> <v-catch> <p>Error $error.message</p> </v-catch>

<v-set-status>

Set the status code.

Rendering will continue as normal. If you want to report a non-success status take a look at the v-check-* tags instead.

namerequiredtemplated
codeyesyes
<form v-name="noddy" >
  <v-action>
    <v-sql>insert into mytable values (22)</v-sql>
    <v-set-status code=201 />
  </v-action>
</form>

<v-redirect>

Redirect the client to the specied path. The path is templated and can be used to redirect after an action or when a page needs a fallback.

namerequiredtemplated
pathyesyes
<form v-name="noddy" >
  <input type="text" name="name" />

  <v-action>
    <v-sql target=$newdog >
      insert into dogs (name) values ($.body.name);
    </v-sql>

    <v-redirect path="/dogs/view/$newdog.id" />
  </v-action>
</form>