CSVTemplate

Summary: Allow representing the same CSV data in different locations using templates.
Version: 2023-11-01
Prerequisites: PHP 7 minimum
Status: stable
Maintainer: PierreRacine
License: GPL2
Categories: CMS, Forms, Tables
Users: (view / edit)
Discussion: CSVTemplate-Talk

Overview

How do I represent the same data in different pages?

CSVTemplate let you format each row of a CSV table saved in a PmWiki page using templates similar to the pagelist directive templates. The CSV page can be produced by Fox forms.

Like in many CMS representing database data using templates, the CSV PmWiki page becomes your database that you can represented with a PmWiki template.

Installation

Download csvtemplate.phpΔ to your cookbook folder and add the following line in your config.php file:

include_once("$FarmD/cookbook/fox/fox.php");

Usage

1 - Dump a CSV file in a PmWiki page (e.g. MemberData). e.g.

lastname;firstname;
Root;Pedro;

2 - Create a template in another page (MemberTemplate) referring to the CSV columns like this: {firstname}. e.g.

[[#member]]
%red%'''{firstname}'''%% {lastname}
[[#memberend]]

3 - Insert the formatted data into any page like this:

(:csvtemplate source=MemberData template=MemberTemplate#memberend header sep=";":)

You can also filter and sort the source data and limit the number of row displayed. All options are documented in csvtemplate.php

A special variable named CSVTemplateCount is automatically set by the renderer to the number of the row being rendered. It can be referenced in the template like this: {CSVTemplateCount}.

Using with Fox

CSVTemplate becomes very useful when you use Fox to generate the CSV page from a form. You can then display data collected with forms in different pages formatted according to your needs.

In this case you can add "foxfilter=csv" to your (:fox ...:) directive to make sure values are trimmed and double-quotes are escaped. The "csv" filter is provided with csvtemplate.php.

Change log / Release notes

2023-11-01 - First version.

See also

Fox

Contributors

PierreRacine

Comments

See discussion at CSVTemplate-Talk

User notes : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.