Household Photo Directory
Imports: 10

This report generates photo directories with household photos, and custom listing preferences for member contact info. It can also display asterisks beside non-members. It requires several of custom fields, which are described in the notes at the top of the code. If you want to create a PDF for this report, you must generate it as HTML, and then convert to PDF. This is because of the way Planning Center's PDF generator handles (or doesn't handle) image files in custom tabs.

Preview

Report Preview


<!--

If you want to create a PDF for this report, you must generate it as HTML,
and then convert to PDF. This is because of the way Planning Center's PDF
generator handles (or doesn't handle) image files in custom tabs.

This photo directory report assumes several custom fields are configured

- primary_contact.custom_tabs.communication_preferences.household_photo
-- This is where you upload a household photo to the primary contact.
-- It should be square (300 to 600px work well) JPEG. If no household
-- photo exists, it will use the primary contact's avatar. If neither exist,
-- it will show a gray square.

- primary_contact.custom_tabs.communication_preferences.hide_household_photo
-- Dropdown with single option: "Hide". 
-- This hides both the household and individual photo from the directory,
-- even if they exist. Display a gray square instead.

- primary_contact.custom_tabs.communication_preferences.listed_address
-- Check-boxes with three options: "Home", "Work", "Other"
-- This controls which addresses are listed for the household. Mailing
-- addresses are only checked for the primary contact.

- person.custom_tabs.communication_preferences.listed_phone
-- Check-boxes with three options: "Home", "Mobile", "Work"
-- This controls which phone numbers are listed for each adult. Home phone
-- numbers are only checked for the primary contact.

- person.custom_tabs.communication_preferences.listed_email
-- Check-boxes with two options: "Home", "Work"
-- This controls which emails are listed for each adult.

- person.custom_tabs.communication_preferences.directory_inclusion
-- Dropdown with single option: "Force Exclude". (You may also add a
-- "Force Include" option for use in list creation.) This will prevent
-- individuals from showing up in the directory, even if their household
-- appears on your list.

This report works best with be two adults per household. Adult children should
be accounted for, but the report has not been well tested in these scenarios.
Contact info is never listed for children. (If you want this listed, you can
change the for-loop to include all household members.)

This report can also add asterisks based on membership status. You can
disable this below if you do not want any asterisks.
{% assign showAsterisks = false %}

Which membership types should be printed without asterisks? List membership
types, separated by commas.

{% capture membershipTypes -%}
Member,Active Participant
{%- endcapture %}
{% assign membershipTypes = membershipTypes | split: ',' %}

-->
  
  
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700|Open+Sans:400,700&display=swap" rel="stylesheet">
  <style>
    html, * {font-family: "Open Sans", sans-serif; line-height:1.4em;}
    @page {margin: .5in 0;}   /*-- PDF margin reset --*/
    body {margin: 0;}
    
    /*-- Fonts --*/
    .adults {font-size: 12pt; font-weight: bold;}
    .children {font-size: 12pt; font-weight: normal;}
    .contacts li {font-size: 10.5pt;}
    
    /*-- Layout --*/
    .avatar {width: 172px; max-height: 258px; border-radius: 10%; overflow: hidden;}
    .avatar > img {width: 100%; display: block;}
    .avatar-noimg {background: #ddd; width: 172px; height: 172px; border-radius: 10%; overflow: hidden;}
    ul {list-style-type: none; display:block; vertical-align:middle; margin:0; padding:0;}
    .household-item  {display: inline-block; width: 172px; vertical-align: top; padding: .5em; page-break-inside: avoid;}
    li.email {overflow-wrap: break-word; word-wrap: break-word;} /*-- allows long emails to break into multiple lines --*/
    
    @media screen {
      /*----- The wrapper class controls the preview frame in the HTML generated report. ----*/
      /*----- Portrait view = max-width: 720px ----*/
      .wrapper 	{padding: 1.5em; border: 1px solid rgb(204,204,204); margin:1.5em auto; max-width:766px;}
    }
    
    @media print {
      .no-print {display: none;}
      body {margin: .25in;} /*----- Adjust this to change the page margins for printing ----*/
    }
  </style>
</head>

<body>
  
  <div class="wrapper">
    <div class="main">
      
      {% for household in households %}
        
        <div class="household-item">
          
          {% assign sameLast = false %}
          {% assign lastname = 'nolastname'%}
          {% assign coupleString = '' %}
          {% assign adultsString = '' %}
          {% assign childrenString = '' %}
          {% assign finalString = '' %}

          {% assign coupleArray = '' | split: '::' %}
          {% assign adultsArray = '' | split: '::' %}
          {% assign childrenArray = '' | split: '::' %}
          {% assign lastNameArray = '' | split: '::' %}
          
          
          <!-- Check if married adults share a last name -->
          
          {% for person in household.adults %}
            {% assign addArray = '' | split: '::' %}
            
            {% if person.active and person.marital_status == 'Married' %}
              {% assign addArray = person.last_name | split: '::' %}
              {% assign lastNameArray = lastNameArray | concat: addArray %}
            {% endif %}
            
            {% assign lastNameArray = lastNameArray | uniq %}
          
          {% endfor %}
          
          {% if lastNameArray.size <= 1 %}
            {% assign sameLast = true %}
          {% endif %}
          
          
          <!-- Find adults and add to appropriate array -->
          
          <!-- Primary contact -->
          
          {% for person in household.adults %}
            
            {% assign addArray = '' | split: '::' %}
            {% assign nameArray = '' | split: '::' %}
            
            {% if household.primary_contact.id == person.id and person.active %}
              
              {% assign addArray = person.name_prefix | split: '::' %}
                {% assign nameArray = nameArray | concat: addArray %}
              {% assign addArray = person.first_name | split: '::' %}
                {% assign nameArray = nameArray | concat: addArray %}
              {% if sameLast and person.marital_status == 'Married' %}
                {% assign addArray = person.name_suffix  | split: '::' %}
                  {% assign nameArray = nameArray | concat: addArray %}
              {% endif %}
              {% unless sameLast and person.marital_status == 'Married' %}
                {% assign addArray = person.last_name | split: '::' %}
                  {% assign nameArray = nameArray | concat: addArray %}
                {% assign addArray = person.name_suffix  | split: '::' %}
                  {% assign nameArray = nameArray | concat: addArray %}
              {% endunless %}
              <!-- Append non-member asterisk -->
              {% assign nameArray = nameArray | join: ' ' | split: '::' %}
              {% if showAsterisks %}
                {% unless membershipTypes contains person.membership %}
                  {% assign addArray = '*' | split: '::' %}
                    {% assign nameArray = nameArray | concat: addArray %}
                  {% assign nameArray = nameArray | join: '' | split: '::' %}
                {% endunless %}
              {% endif %}
              {% assign addArray = nameArray | join: ' ' | split: '::' %}
              <!-- End name generation -->
          
              {% if person.marital_status == 'Married' %}
                {% assign coupleArray = coupleArray | concat: addArray %}
                {% else %}
                  {% assign adultsArray = adultsArray | concat: addArray %}
              {% endif %}
            
            {% endif %}
          
          {% endfor %}
          
          <!-- Non-primary adults -->
          {% for person in household.adults %}
            
            {% assign addArray = '' | split: '::' %}
            {% assign nameArray = '' | split: '::' %}
            
            {% if household.primary_contact.id != person.id and person.active and person.custom_tabs.communication_preferences.directory_inclusion.value != 'Force Exclude' %}
              
              <!-- Begin adult name generation -->
              {% assign addArray = person.name_prefix | split: '::' %}
                {% assign nameArray = nameArray | concat: addArray %}
              {% assign addArray = person.first_name | split: '::' %}
                {% assign nameArray = nameArray | concat: addArray %}
              {% if sameLast and person.marital_status == 'Married' %}
                {% assign addArray = person.name_suffix  | split: '::' %}
                  {% assign nameArray = nameArray | concat: addArray %}
              {% endif %}
              {% unless sameLast and person.marital_status == 'Married' %}
                {% assign addArray = person.last_name | split: '::' %}
                  {% assign nameArray = nameArray | concat: addArray %}
                {% assign addArray = person.name_suffix  | split: '::' %}
                  {% assign nameArray = nameArray | concat: addArray %}
              {% endunless %}
              <!-- Append non-member asterisk -->
              {% assign nameArray = nameArray | join: ' ' | split: '::' %}
              {% if showAsterisks %}
                {% unless membershipTypes contains person.membership %}
                  {% assign addArray = '*' | split: '::' %}
                    {% assign nameArray = nameArray | concat: addArray %}
                  {% assign nameArray = nameArray | join: '' | split: '::' %}
                {% endunless %}
              {% endif %}
              {% assign addArray = nameArray | join: ' ' | split: '::' %}
              <!-- End name generation -->
              
              
              {% if person.marital_status == 'Married' %}
                {% assign coupleArray = coupleArray | concat: addArray %}
                {% else %}
                  {% assign adultsArray = adultsArray | concat: addArray %}
              {% endif %}
            
            {% endif %}
          
          {% endfor %}
          
          <!-- Generate couple/adult strings -->
          
          {% if coupleArray.size > 0 %}
            {% if sameLast %}
              {% assign coupleString = coupleArray | join: ' & ' | append: ' ' | append: household.primary_contact.last_name %}
              {% else %}
                {% assign coupleString = coupleArray | join: ' & ' %}
            {% endif %}
          {% endif %}
          
          {% assign adultsString = adultsArray | join: ', ' %}
          
          <!-- If there's a couple, set them as finalString; strip last name from other adults and them add to childrenArray -->
          {% if coupleString.size > 1 %}
            {% assign finalString = coupleString %}
            
            {% assign removeLastName = household.primary_contact.last_name | prepend: ' ' %}
            {% assign adultsString = adultsString | remove: removeLastName %}
            {% assign childrenArray = adultsString | split: ', ' %}
            
            <!-- Otherwise use unmarried adults as finalString -->
            {% else %}
              {% assign finalString = adultsString %}
          {% endif %}
                    
          
          <!-- Find children and add to array -->
          
          {% for person in household.children %}
          
            {% assign addArray = '' | split: '::' %}
            {% assign nameArray = '' | split: '::' %}
            
            {% if person.active and person.custom_tabs.communication_preferences.directory_inclusion.value != 'Force Exclude' %}
            
              <!-- Begin child name generation -->
              {% assign addArray = person.name_prefix | split: '::' %}
                {% assign nameArray = nameArray | concat: addArray %}
              {% assign addArray = person.first_name | split: '::' %}
                {% assign nameArray = nameArray | concat: addArray %}
              {% unless sameLast and person.last_name == household.primary_contact.last_name %}
                {% assign addArray = person.last_name | split: '::' %}
                  {% assign nameArray = nameArray | concat: addArray %}
              {% endunless %}
              {% assign addArray = person.name_suffix  | split: '::' %}
                {% assign nameArray = nameArray | concat: addArray %}
              <!-- Append non-member asterisk -->
              {% assign nameArray = nameArray | join: ' ' | split: '::' %}
              {% if showAsterisks %}
                {% unless membershipTypes contains person.membership %}
                  {% assign addArray = '*' | split: '::' %}
                    {% assign nameArray = nameArray | concat: addArray %}
                  {% assign nameArray = nameArray | join: '' | split: '::' %}
                {% endunless %}
              {% endif %}
              {% assign addArray = nameArray | join: ' ' | split: '::' %}
              <!-- End name generation -->
              
              {% assign childrenArray = childrenArray | concat: addArray %}
            
            {% endif %}
            
            {% assign childrenString = childrenArray | join: ', ' %}
                      
          {% endfor %}
          
          
          <!-- Begin generating entry -->
          
          
          <!-- Insert household or individual photo -->
          
          {% if household.primary_contact.custom_tabs.communication_preferences.hide_household_photo.value != 'Hide' %}
            {% if household.primary_contact.custom_tabs.communication_preferences.household_photo.value.size > 1 %}
              {% assign imgurl = household.primary_contact.custom_tabs.communication_preferences.household_photo.value | split: '&quot;' %}
              {% assign imgurl = imgurl[1] %}
          <div class="avatar">
            <img src="{{- imgurl -}}"></img>
          </div>
              {% else %}
                {% unless household.primary_contact.photo_url contains 'initials' %}
                  {% assign imgurl = household.primary_contact.photo_url | split: '?' %}
                  {% assign imgurl = imgurl[0] | append: '?g=600x600' %}
                  <div class="avatar">
                    <img src="{{- imgurl -}}"></img>
                  </div>
                  {% else %}
                  <div class="avatar-noimg"></div>
                {% endunless %}
            {% endif %}
            {% else %}
              <div class="avatar-noimg"></div>
          {% endif %}
          
          <div class="adults">
            {{ finalString }}
          </div>
          
          <div class="children">
            {{ childrenString }}
          </div>
          
          
          <div class="contacts">
            
            <ul>
              
              {% assign includetest = household.primary_contact.custom_tabs.communication_preferences.listed_address | join: ', ' %}
                  
                  {% for address in household.primary_contact.addresses %}
                    {% if includetest contains address.location and address.location == 'Other' %}
                      <li class="address">{{ address.street_line_1 }}{% if address.street_line2 %}<br />{{ address.street_line_2 }}{% endif %}<br />{{ address.city }}, {{ address.state }} {{ address.zip | slice: 0, 5 }}</li>
                    {% endif %}
                  {% endfor %}
                  
                  {% for address in household.primary_contact.addresses %}
                    {% if includetest contains address.location and address.location == 'Home' %}
                      <li class="address">{{ address.street_line_1 }}{% if address.street_line2 %}<br />{{ address.street_line_2 }}{% endif %}<br />{{ address.city }}, {{ address.state }} {{ address.zip | slice: 0, 5 }}</li>
                    {% endif %}
                  {% endfor %}
                  
              {% assign includetest = household.primary_contact.custom_tabs.communication_preferences.listed_phone | join: ', ' %}
                  {% for phone_number in household.primary_contact.phone_numbers %}
                    {% if includetest contains phone_number.location and phone_number.location == 'Home' %}
                      <li class="phone">{{ phone_number.number }} ({{ phone_number.location }})</li>
                    {% endif %}
                  {% endfor %}
              
              {% for person in household.adults %}
                {% if person.active %}
                  
                  {% assign includetest = person.custom_tabs.communication_preferences.listed_phone | join: ', ' %}
                  {% for phone_number in person.phone_numbers %}
                    {% if includetest contains phone_number.location and phone_number.location != 'Home' %}
                      <li class="phone">{{ phone_number.number }} ({{ person.first_name }})</li>
                    {% endif %}
                  {% endfor %}
                  
                  {% assign includetest = person.custom_tabs.communication_preferences.listed_email | join: ', ' %}
                  {% for email in person.emails %}
                    {% if includetest contains email.location %}
                      <li class="email">{{ email.address }} ({{ person.first_name }})</li>
                    {% endif %}
                  {% endfor %}
                
                {% endif %}
              
              {% endfor %}
            </ul>
          
          </div>
          
        </div>
      
      {% endfor %}
        
    </div>
  </div>

</body>
</html>