Hi Yaron,
The code to enable the table display on PracticalPlants resides in a separate skin-companion extension, but I'd be glad to extend the functionality to offer a table view baked into the core.

How do you envision table headers being defined? Something like....

{{{for template|Reference|multiple|display=table|table headers=One;Two;Three;Four;Five;etc}}}


El 30/10/2012, a las 17:15, Yaron Koren escribió:

Hi Andru,

One has to register to see the form link you included, but I'm glad I did, because that form looks great! Turning a multiple-instance template form section into a spreadsheet-like interface is a fairly obvious enhancement that I, and other people, have wanted for a long time. So however we can get this functionality into SF, I think it would be great.

I guess there are two issues: how to make SF's display of multiple-instance templates extensible so that it can allow further customizations like yours, and how to specifically add this kind of spreadsheet/table display. (You could argue that there's a third issue, of how to make all of SF's HTML display more extensible.)

For the 2nd issue, I could imagine that there could be a new parameter, like "display=", so that one could call something like the following:

{{{for template|Reference|multiple|display=table}}} (or "spreadsheet")

I only skimmed through your code, but I assume the code you added to enable this specific display is outside of the SF code, and possibly hardcoded for your specific data structure? If so, what do you think about the idea of adding this kind of thing directly into Semantic Forms, in addition to the new hooks?


On Tue, Oct 30, 2012 at 9:29 AM, Andru Vallance <andru@tinymighty.com> wrote:
I inadvertently sent this from the wrong email account earlier, and it seems to have vanished into a black hole. I'm resending again, from the correct email account. My apologies if the other turns up as a duplicate.

For my work on Practical Plants (http://practicalplants.org/wiki), I needed to be able to control the HTML which was output by multiple template instances. Currently the HTML is hardcoded within the SF parser and there are no hooks available to modify it's output. While my need may be a fringe case, I think hardcoded HTML with no way to override it encourages hacking the core files: A Very Bad Thing. I'd like to submit my changes for inclusion into SF core, so I'm looking for feedback on the changes I'm proposing. I've attached a patch for SF_FormPrinter.php and SemanticForms.php and a new class file SF_MultipleTemplate.php, at the end of this email. 

I've made the following SF hooks available to modify the HTML output of a multiple template instance. In order to make these hooks flexible, I wanted to be able to supply an object instance which contained information about the Multiple Template Instance being parsed. To do this, I extracted most of the logic for outputting multiple template instances into a new class SFMultipleTemplate which is responsible for defining the default HTML (which is currently hardcoded in SFFormPrinter),  and for running the following hooks, which it passes the default html by reference to allow for modification, and the SFMultipleTemplate instance which is calling the hook, to give access to data about the Multiple Template Instance in question.

Here are the hooks I've created, based on the default HTML currently used.

sfMultipleInstanceTemplateBeforeHTML (String &$html, SFMultipleTemplate $template)
Allows the customisation of the HTML which is output before the list of template instances. 

sfMultipleInstanceTemplateAfterHTML (String &$html, SFMultipleTemplate $template)
Allows the customisation of the HTML which is output after the list of template instances.

sfMultipleInstanceTemplateHTML (String &$html, String $content, SFMultipleTemplate $template)
Allows the customisation of the html which wraps a multiple template instance item.

sfMultipleInstanceTemplateAdderHTML (String &$html, String $content, SFMultipleTemplate $template)
Same as above, except this sets the hidden multiple template instance item which is cloned by the frontend javascript when the add button is clicked.

sfMultipleInstanceTemplateInnerHTML (String &$html, String $section, SFMultipleTemplate $template)
Allows the customisation of the html of the multiple template instance item. The html returned by this must contain the close and reorder icons. Passing some isolated default html for those icons, or providing get methods in SFMultipleTemplate might be a good idea.

Practical Plants Use Case
I use these hooks to render multiple template instance items as rows of a table for my references. You can see it in action here:

This is implemented with the following hook handlers in my skin's related extension. Note that by extracting the Multiple Template Instance functionality into an object, I am able to check the template name to customise output on a per-instance basis. 

function sfMultipleInstanceTemplateBeforeHTML(&$html, $template){
if($template->template_name === 'Reference'){
$html = '
<div class="multipleTemplateWrapper">
<table class="table">
<th class="ref-type">Type</th>
<th class="ref-id">Identifier</th>
<th class="ref-author">Author</th>
<th class="ref-title">Title</th>
<th class="ref-source">Source</th>
<th class="ref-url">URL/ISBN</th>
<th class="ref-date">Date</th>
<th class="ref-buttons"></th>
<tbody class="multipleTemplateList">';
return true;
function sfMultipleInstanceTemplateAfterHTML(&$html, $template){
if($template->template_name === 'Reference'){
$html = '</tbody></table>';
$html .= $template->addButtonHTML();
$html .= '</div>';
return true;
function sfMultipleInstanceTemplateHTML(&$html, $content, $template){
if($template->template_name === 'Reference'){
$html = '<tr class="multipleTemplateInstance multipleTemplate">'.$content.'</tr>';
return true;

function sfMultipleInstanceTemplateAdderHTML(&$html, $content, $template){
if($template->template_name === 'Reference'){
$html = '<tr class="multipleTemplateStarter" style="display:none">'.$content.'</tr>';
return true;

function sfMultipleInstanceTemplateInnerHTML(&$html, $section, $template){
global $sfgScriptPath;
if($template->template_name === 'Reference'){
  //we have to str_replace some faux td elements since mediawiki doesn't allow <td> elements in wikitext without an enclosing table element
$html =   str_replace('-!/td!-','</td>',str_replace('-!td!-', '<td>', $section)).'<td>'
. '<span class="removeButton"><a class="btn btn-link remover"><i class="icon-remove"></i></a></span>'
. '<span class="instanceRearranger"><img src="'.$sfgScriptPath.'/skins/rearranger.png" class="rearrangerImage"></span>'
. '</td>';
return true;

Patch for SF_FormPrinter.php

Patch for SemanticForms.php

New class file SF_MultipleTemplate.php

Any feedback would be appreciated. I'd love to have this included in the core so I can implement the functionality I need without having a custom core hack!

Andru Vallance

Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
Semediawiki-devel mailing list

WikiWorks · MediaWiki Consulting · http://wikiworks.com