Omit Fields in Print View if Empty Value

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
primitive_man
AppGini Super Hero
AppGini Super Hero
Posts: 54
Joined: 2014-03-09 20:20

Omit Fields in Print View if Empty Value

Post by primitive_man » 2015-05-02 11:27

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...

primitive_man
AppGini Super Hero
AppGini Super Hero
Posts: 54
Joined: 2014-03-09 20:20

Re: Omit Fields in Print View if Empty Value

Post by primitive_man » 2015-05-07 12:14

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!

primitive_man
AppGini Super Hero
AppGini Super Hero
Posts: 54
Joined: 2014-03-09 20:20

Re: Omit Fields in Print View if Empty Value

Post by primitive_man » 2015-05-07 12:33

Ooops... forgot...

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

patsd102
Veteran Member
Posts: 83
Joined: 2013-01-15 19:59

Re: Omit Fields in Print View if Empty Value

Post by patsd102 » 2015-05-07 18:01

Thanks for sharing

Pat

Post Reply