Topic: Hiding empty template variables in Ditto template  (Read 1148 times)

Pages: [1]   Go Down

#1: 15-Oct-2007, 05:06 AM

worchyld
Posts: 349

I love MODx!

I have a basic ditto template which has various template variables in the document and looks like this:

Code:
<h2>[+tplvar_company_name+]</h2>
<p>[+tplvar_description+]</p>
<p>[+tplvar_address+]<br />
[+tplvar_contact_name+]<br />
<strong>[+tplvar_contact_position+]</strong>
</p>
<p>[+tplvar_telephone+]<br />
[+tplvar_fax+]<br />
[+tplvar_mobile+]<br />
[+tplvar_skype+]<br />
[+tplvar_email+]<br />
[+tplvar_website+]
</p>
<p>
<a href="#top">^ Top</a>
</p>

However sometimes there might not be any "skype", "email", or "telephone" data, so this means I get a lot of blank spaces because of the breaks (br).

Q1. I would like to know how to tell Ditto to ignore any template variable (and the BR after it) if it is blank.

Also, when I created template variables it asked me for a label (ie: "Website", "URL" or "company name").

Q2. Is it possible for me to use these labels in my Ditto template without having me to re-typing them?

ie:
Code:
[+some_template_variable_label+] - [+some_template_variable_value+]<br />

Many thanks.

#2: 15-Oct-2007, 09:35 AM

Coding Team
heliotrope
Posts: 2,528

WWW
Hi,

Quote
Q1. I would like to know how to tell Ditto to ignore any template variable (and the BR after it) if it is blank.

Code:
[+tplvar_fax:isnot=``:then=`[+tplvar_fax+]<br />`+]

for more information about PHx see the wiki

:-)
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.