WikiTask Tutorial/Rythm Engine


Wolfgang Fahl


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

sidif input

id='person'

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

id='rtemplate'

@// This is a rythm template
@// the args are the standard wikiTask arguments
@args() {
  String title 
  String logo
  org.sidif.wiki.WikiTask 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) {
      this.id = id;
      this.name = 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());
    persons.add(person);
  }
}
@// 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 @person.name ===
id is @person.id<br>
name is @person.name
}

wiki task

{{wikitask|cmd=runtemplate|input=person|template=rtemplate|engine=Rythm|targetpage=WikiTask_Tutorial/person}}

runtemplate -> WikiTask_Tutorial/person

sidif input[edit]

id='person'

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[edit]

id='rtemplate'

@// This is a rythm template
@// the args are the standard wikiTask arguments
@args() {
  String title 
  String logo
  org.sidif.wiki.WikiTask 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) {
      this.id = id;
      this.name = 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());
    persons.add(person);
  }
}
@// 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 @person.name ===
id is @person.id<br>
name is @person.name
}

wiki task[edit]

{{wikitask|cmd=runtemplate|input=person|template=rtemplate|engine=Rythm|targetpage=WikiTask_Tutorial/person}}

runtemplate -> WikiTask_Tutorial/person

🖨 🚪