Hello,
For my first post, I whish to start by thanking people behind modx for giving us a so valuable tool.
I’m currently working on a HTML -> PDF conversion under ModX Evo 1.05. To do so, I adapted a
previous thread. I modified the code in order to use snippets when generating PDFs. Here is the code of my snippet (called GeneratePDF):
<?php
global $modx;
# Define a unique name for each generated PDF
$stamp = time();
$nomFichier = $modx->getLoginUsername() . '_' . $stamp;
# Getting back info generated by modX
if (isset($_GET['docid'])) {
$id = $modx->db->escape($_GET['docid']);
$doc = $modx->getPageInfo($id, 1, 'content');
$title = $modx->getPageInfo($id, 1, 'longtitle');
}
$output = '<h1>' . $title['longtitle'] . '</h1>' . $doc['content'];
# Execute all Snippets present on this page (using TV listeSnippets)
//$listeSnippets = explode(",", &$liste);
$liste = isset($liste) ? $liste:'';
$listeSnippets = explode(",", $liste);
foreach($listeSnippets as $snippet) {
$snippetCalls = explode("?", $snippet);
$nomSnippet = $snippetCalls[0];
if ( sizeof($snippetCalls) == 2 ) {
$paramTous = $snippetCalls[1];
$interms = explode("&", $paramTous);
$params = array();
foreach($interms as $paramInterm) {
if (trim($paramInterm) != '') {
$paramInterm = preg_replace('/\`/', "", $paramInterm);
$interms = explode("=", $paramInterm);
if (sizeof($interms) == 2) {
$params[$interms[0]] = $interms[1];
}
}
}
$output .= $modx->runSnippet($nomSnippet, $params);
} else {
$output .= $modx->runSnippet($nomSnippet);
}
}
# Delete all snippets call that will otherwise be visible into the PDF
$output = preg_replace('/\[!.{1,}!\]/', "", $output);
# Write PDF
$basePath = $modx->config['base_path'];
$pluginPath = $basePath . 'assets/lib/tcpdf/';
if ($_GET['contentType'] == 'pdf') {
include $pluginPath . 'examples/myexample.php';
}
?>
I created a template variable called "listeSnippets" (tested types: text and rich text). This TV gets the name (and parameters) of the snippets that have to be processed when generating a PDF. For example:
mysnippet, eForm? &formid=`informC` &eFormOnBeforeMailSent=`storeInforme` &tpl=`informC` &noemail=`true`
In my template, I added the snippet call:
[!GeneratePDF? &liste=`[*listeSnippets*]`!]
The PDF is generated correctly, but only the first snippet is processed. When tracing the $liste arg in the snippet, I got: "mysnippet, eFor". Has somebody an idea on why the second snippet call is truncated?
Thanks in advance.