Page 1 of 1

Omit Fields in Print View if Empty Value

Posted: 2015-05-02 11:27
by primitive_man
Hi, I have several reports wherein parts are optional.

Anyone know how I can Omit them during printing if there value is empty. For example,

if (<%%VALUE(notes)%%>) = '') {
echo $this;
} else { echo $that; }

Of course, <%%VALUE(notes)%%> is part of the templating system and this is simply replaced by the value string.

So I really need to know how check whether this templated string is empty or not...

Re: Omit Fields in Print View if Empty Value

Posted: 2015-05-07 12:14
by primitive_man
Figured this out after a marathon drinking session last night... who says beers good for nothing!

The answer lies in two files:

The '*_templateDVP.html' file and the '*_dml.php' files. (Place your own filename at the *)

Example:
notes_templateDVP.html file: I'd previously modified the template here but bear with me and had this section which printed out the older style notes:

Code: Select all

<div class="form-group" style="border-bottom: dotted 1px #DDD;">
<label class="col-xs-3 control-label">Notes (Old Style)</label>
<div class="col-xs-9">
<p class="form-control-static"><%%VALUE(Note)%%></p>
</div>
</div>
notes_dml.php file:

Code: Select all

$templateCode=str_replace('<%%VALUE(Note)%%>', nl2br($row['Note']), $templateCode);
CHANGES:
notes_templateDVP.html file:
Replaced the original code with:

Code: Select all

<%%VALUE(oldNotes)%%>
notes_dml.php file:
ADDED:

Code: Select all

if (!empty($row['Note']))
{
$templateCode=str_replace('<%%VALUE(oldNotes)%%>','<div class="form-group" style="border-bottom: dotted 1px #DDD;"><label class="col-xs-3 control-label">Notes (Old Style)</label><div class="col-xs-9"><p class="form-control-static"><%%VALUE(Note)%%></p></div></div>', $templateCode);
}
The end result, is that if the $row['Note'] is NOT empty, the notes get printed out. If they are empty, they're not.

It's not an elegant solution by any means - and if I'm ever required to have to do this to many fields, I'll automate it using a hook.

Have a nice day!

Re: Omit Fields in Print View if Empty Value

Posted: 2015-05-07 12:33
by primitive_man
Ooops... forgot...

you should usually add your template code above the 'if($dvprint)' section of any field you wish to check.

Re: Omit Fields in Print View if Empty Value

Posted: 2015-05-07 18:01
by patsd102
Thanks for sharing

Pat