Create a new page for each table

I have this cod which creates 3 tables on the same page:

#foreach($j in [0…2])
(% id=“tableid” class=“doOddEven filterable grid sortable” %)
(% class=“sortHeader” %)|=Student Name |= Math Mark|= Biology Mark|=Average
#foreach($i in [0…5])
| | | |

How can I modify it such that it will create a new page for each table? (At one iteration the written code will create a new page with a single table in the main page, “PageWithTables”)
The structure to be something like this:

To create a page see

I succeed to create other pages, but how I do to execute my velocity code from my page to that pages(with tables)?

#set($tabel = 'TabelNotare.Tabel')
#foreach($j in [0..2])
#set($tabnume = $tabel + $j)
#set ($newDoc = $xwiki.getDocument($tabnume))
(% id="tableid" class="doOddEven filterable grid sortable" %)
(% class="sortHeader" %)|=Student Name |= Math Mark|= Biology Mark|=Average
#foreach($i in [0..5])
   | | | | 
#set ($discard = $"Comment", true))

That code creates my pages but doesn’t create a table on each page. It creates all tables on the same page which contains the code.
How can I rezolve that?

If what you want is to set the content of the new page, then use #set ($discard = $newDoc.setContent("...")).

But it doesn’t work to put my velocity code for table there.

Hi Paula,

Do you want to duplicate the Velocity code on each page you create? I doubt you want that because it makes the code hard to maintain. For instance, if later you want to add a new column to your table then you need to update all the pages you have previously created. The most trivial and natural solution in your case is to use an include:

  • Put the Velocity code that generates the table in a separate page, e.g. TabelNotare.TableGenerator

  • Then include that page in the pages your create:

    $newDoc.setContent('<include reference="TabelNotare.TableGenerator"/>')

But this is still not perfect. If at some point in the future you want to rename or move the table generator page then you’ll have to update all the existing pages (XWiki doesn’t do this for your yet). Best is to use the sheet system. See . In any case, I recommend following .

Hope this helps,