• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Contribution - Email Template Plugin: Output textarea into dynamic HTML Table

nbradshaw

Active Member
I was searching for a way to output my textarea string that is separated by line break "/n" into a dynamic HTML table on an email template.

I needed this because I have users that paste lot of information into a textarea (separated by line break - and I didn't want the email to be a huge long single column list that goes on forever.

Original Output:
$this->data['simplex_alert___affected_site_list'];
Site 1
Site 2
Site 3
Site 4
Site 5
Site 6
etc...

New Output (With dynamic table) and options on how many columns you want.
Site 1 | Site 2 | Site 3
Site 4 | Site 4 | Site6
etc...

I did not create this - but it did take a while to find...so I will take credit for finding it :) I also added the explode piece into the original contributors code. Obviously a big thanks to the original contributor.

Contributor Site

PHP:
// Numeric array with data that will be displayed in HTML table

//Fabrik element
$str = $this->data['simplex_alert___affected_site_list'];

$aray1 = explode("\n", $str);
$aray = array_unique($aray1);
$nr_elm = count($aray);        // gets number of elements in $aray

// Create the beginning of HTML table, and of the first row
$html_table = '<table border="1 cellspacing="0" cellpadding="2""><tr>';
$nr_col = 6;       // Sets the number of columns

// If the array has elements
if ($nr_elm > 0) {
  // Traverse the array with FOR
  for($i=0; $i<$nr_elm; $i++) {
    $html_table .= '<td>' .$aray[$i]. '</td>';       // adds the value in column in table

    // If the number of columns is completed for a row (rest of division of ($i + 1) to $nr_col is 0)
    // Closes the current row, and begins another row
    $col_to_add = ($i+1) % $nr_col;
    if($col_to_add == 0) { $html_table .= '</tr><tr>'; }
  }

  // Adds empty column if the current row is not completed
  if($col_to_add != 0) $html_table .= '<td colspan="'. ($nr_col - $col_to_add). '"> </td>';
}

$html_table .= '</tr></table>';         // ends the last row, and the table

// Delete posible empty row (<tr></tr>) which cand be created after last column
$html_table = str_replace('<tr></tr>', '', $html_table);

echo $html_table;        // display the HTML table
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top