v-creator

site is v-created

SourceForge.net Logo

Examples

Dynamic Data from Databases

The table below shows a simple LIVE v-creator example in action.

Title Author ISBN
Cascading Style Sheets: The Definitive Guide, 2nd Edition Eric Meyer 0-596-00525-3
Essential CVS Jennifer Vesperman 0-596-00459-1
HTML & XHTML: The Definitive Guide, 5th Edition Chuck Musciano, Bill Kennedy 0-596-00382-X
Learning PHP 5 David Sklar 0-596-00560-1
Learning the vi Editor, 6th Edition Linda Lamb, Arnold Robbins 1-56592-426-6
Programming PHP Rasmus Lerdorf, Kevin Tatroe 1-56592-610-2
Understanding the Linux Kernel, 2nd Edition Daniel P. Bovet, Marco Cesati 0-596-00213-0

The example was created using an automatically generated database module. The figure below shows the steps to creating the module.

Generating a database module
  1. A simple database table called books with the columns book_id, book_title, author and ISBN was created
  2. The supplied genDBmodule utility was then run against the database table to create a database module called books.php
  3. A few simple changes were then made to the generated code to order by book title and flag rows as odd or even
  4. The books.php file is copied to the user modules directory
In total less than 5 minutes work.

To generate the above table the following HTML & v-creator tags were used:

<table>
  <tr>
    <th>Title<th>
    <th>Author<th>
    <th>ISBN<th>
  <tr>
  |{LOOP:books}|
  <tr |{COND:odd_row}|style="background: #dfdfdf;"|{CEND}|>
    <td>|{DATA:book_title}|<td>
    <td>|{DATA:author}|<td>
    <td>|{DATA:isbn}|<td>
  <tr>
  |{LEND}|
<table>

Module Reuse

We can now reuse the book module to produce other dynamic elements.

A drop down list of books:

<select>
  |{book_id=VC_NULL}|
  |{LOOP:books}|
    <option value="|{DATA:book_id}|">|{DATA:book_title}|<option>
  |{LEND}|
<select>

Or lists of data:

<ul>
  |{book_id=VC_NULL}|
  |{LOOP:books}|
    <li>|{DATA:book_author}|</li>
  |{LEND}|
</ul>

Conditional Content

v-creator also makes it easy to have content displayed based on conditional tests. As the books module has an odd/even flag it will be used to demonstrate conditional testing by only showing books from even database rows:

<ul>
  |{book_id=VC_NULL}|
  |{LOOP:books}|
    |{COND:odd_row}|
      <li>|{DATA:book_author}|</li>
    |{CEND}|
  |{LEND}|
</ul>