A
A
Alexander2020-01-22 19:08:22
PHP
Alexander, 2020-01-22 19:08:22

How to remove empty lines created by Smarty?

Below is the part of the code which creates pdf with customer information. It works, but if some value (for example parish or state) is empty, then it creates empty row in the document.
1) First example

{sle n=c p=receiver/contact}
{foreach from=$c item=i name=contacts}
{gv c=$i p=person/name}
{gv c=$i p=organization/name}
{gv c=$i p=address/street} {gv c=$i p=address/house_nr} {gv c=$i p=address/appartment_nr}
{gv c=$i p=address/zip_code} {gv c=$i p=address/city}
{gv c=$i p=address/parish}
{gv c=$i p=address/state}
{if !$smarty.foreach.contacts.last}{/if}
{/foreach}

2) Second example
{if xpc(“gv“,“occupation“)}{gv p=occupation}{else}{/if}

If occupation is empty in my DMS, then empty row will be created. If there is variable value is empty, then code should just skip that part and go further without creating empty spaces. Thanks for help!
gv (get value) This tag is used to display the contents of the fields.
Parameters: Name Description
p path. Specifies the location in the XML tree
c context. Specifies the context in which a value search is performed.
ttype. Specifies the field type. If not set, it will be displayed exactly as it is in the input.
req Required. Specifies whether the corresponding variable is required. default is "true"
empty If the value is empty or missing (in the latter case req = false), the value of this variable is returned. For example. {gv p = my value req = false empty = empty}.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lubezniy, 2020-01-22
@lubezniy

May you try to use something like:
{if isset($person.name)}here is your gv code{/if}
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question