WikiTask Tutorial/Rythm Engine

From BITPlan Wiki
Jump to navigation Jump to search

The alternative TemplateEngine Rythm can be used for defining templates. Rythm has better direct Java support then Freemarker.

sidif input


john isA person
1 is id of john
"John Doe" is name of john
tom isA person
2 is id of tom
"Tom Scott" is name of tom

rythm template


@// This is a rythm template
@// the args are the standard wikiTask arguments
@args() {
  String title 
  String logo wikiTask
  org.sidif.triple.TripleStore tripleStore

@// here some java code is declared and executed
@// the resulting variables can be used as template variables later
  class Person {
    public String id;
    public String name;
    Person (String id, String name) { = id; = name;
  } // Person

  org.sidif.triple.TripleQuery personQuery=tripleStore.query().query(null,"isA","person");
  List<Person> persons=new ArrayList<Person>();
  for (org.sidif.triple.Triple personTriple:personQuery.getTriples()) {
    org.sidif.triple.Triple idtriple=tripleStore.query().selectSingle(personTriple.getSubject(),"id",null);
    org.sidif.triple.Triple nametriple=tripleStore.query().selectSingle(personTriple.getSubject(),"name",null);
    Person person = new Person(idtriple.getObject().toString(), nametriple.getObject().toString());
@// now we can loop over the list of persons we just created above
@// this part is the real "template" so the wiki page will contain the stuff output here
== Persons ==
@for(Person person:persons) {
=== Person ===
id is<br>
name is

wiki task


runtemplate -> WikiTask_Tutorial/person