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...
Omit Fields in Print View if Empty Value
-
- AppGini Super Hero
- Posts: 54
- Joined: 2014-03-09 20:20
-
- AppGini Super Hero
- Posts: 54
- Joined: 2014-03-09 20:20
Re: Omit Fields in Print View if Empty Value
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:
notes_dml.php file:
CHANGES:
notes_templateDVP.html file:
Replaced the original code with:
notes_dml.php file:
ADDED:
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!
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>
Code: Select all
$templateCode=str_replace('<%%VALUE(Note)%%>', nl2br($row['Note']), $templateCode);
notes_templateDVP.html file:
Replaced the original code with:
Code: Select all
<%%VALUE(oldNotes)%%>
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);
}
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!
-
- AppGini Super Hero
- Posts: 54
- Joined: 2014-03-09 20:20
Re: Omit Fields in Print View if Empty Value
Ooops... forgot...
you should usually add your template code above the 'if($dvprint)' section of any field you wish to check.
you should usually add your template code above the 'if($dvprint)' section of any field you wish to check.