CSVTemplate-Talk

Summary: Talk page for CSVTemplate.
Maintainer: PierreRacine
Users: (View / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

Hi Pierre! To use CSV data as data source, and to be able to display data via templates in different ways, is nice! Could you incorporate the following modification:

  • for template variables to use the usual PmWiki syntax of {$$variable} , not {variable}.

Also I am confused about the header option. If I set it to 0 I get no content output, or rather empty fields. What would be nice to have the option, within the display template, to set Column headings for instance (if one wants to generate a custom table). Something similar to (:template first:) in pagelist templates, basically optional header content, which will not get repeated for every line output. - I also noted quite a few warnings coming up when using PHP 8, which I do, the usual warnings when variables are not set. Thanks for the recipe! I will continue my tests and see how I can integrate it with Fox. Very promising! - HansB 3-11-2023

PS: Looking at the code for the filter option: this may well be a security risk because the use of eval() function without specific input checks. HansB

Hi Hans,

What is the advantage of using {$$variable} instead of {variable}?

I guess the problem with the header option is that you are trying to set it to something when it should just be present or not. Maybe you have something in your header that I don't use myself and I did not test with it.

I did not test with PHP 8 yet.

Any idea how to check inputs before passing them to eval()?

Pierre

HansB : Re: Markup definitions: there is always the possibility that the definition is too general, which can lead to unexpected results. In PmWiki the convention has been to use {$$var} for template variables. It is done for pagelist templates, and I've implemented this markup for Fox templates. Of course you don't need to follow such conventions. One other advantage may be that you could simply call FoxVarReplace function, like

 $str = FoxVarReplace($pagename, $arg, '', $template); 

and FoxVarReplace will substitute each {$$var} in the template with a matching value from the $arg array and returns the so substituted template as string. That would also eliminate one call to eval().

Re: eval(): I woulkd avoid it at all cost, and have never needed to use it. The php manual says:

Caution :The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.

Talk page for the CSVTemplate recipe (users).