ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

vCard Generation, PHP, and conditionals

June 20, 2012 5:24pm

Subscribe [1]
  • #1 / Jun 20, 2012 5:24pm

    ljanocha

    2 posts

    I am dynamically generating vCards for employees and using php to add the correct header information

    Sample:

    {exp:channel:entries channel="lawyer|analyst" limit="1" url_title="{segment_3}"}
    BEGIN:VCARD
    VERSION:3.0
    REV:{entry_date}
    FN:{professional_first_name} {professional_last_name}
    N:{professional_last_name};{professional_first_name} {professional_initial}.
    TITLE:{professional_title}
    ORG: Organization
    
    {professional_location limit="1"}
    ADR;TYPE=WORK:{office}{office_address}{street};{street_2};{city} {region} {postal_code};{country}{/office_address}{/office}
    LABEL;TYPE=WORK:{office}{office_address}{street}\n{street_2}\n{city} {region} {postal_code}\n{country}{/office_address}{/office}
    TEL;TYPE=WORK;VOICE:{phone}
    TEL;TYPE=WORK;FAX:{office}{office_fax}{/office}{/professional_location}
    
    {professional_location offset="1" limit="1"}
    ADR;TYPE=POSTAL:{office}{office_address}{street};{street_2};{city} {region} {postal_code};{country}{/office_address}{/office}
    LABEL;TYPE=POSTAL:{office}{office_address}{street}\n{street_2}\n{city} {region} {postal_code}\n{country}{/office_address}{/office}
    TEL;TYPE=POSTAL;VOICE:{phone}
    TEL;TYPE=POSTAL;FAX:{office}{office_fax}{/office}
    {/professional_location}
    
    EMAIL;TYPE=internet,pref:{professional_email}
    URL;TYPE=WORK: <a href="http://www.organization.com">http://www.organization.com</a>
    TZ:-0400
    END:VCARD
    {/exp:channel:entries}
    
    <?php header('Content-Type: text/x-vcard; charset=utf-8');header('Content-Disposition: attachment; filename="{segment_3}.vcf"'); exit(); ?>

    I am running into a issue when trying to do a few conditional checks within the channels entries loop - All conditional text is output as plain text within the card with the variables parsed. This lead to my messy implementation of the 2nd office address matrix utilizing the offset param as some users have a 2nd office they work out of and some do not. I also needed to change the TYPE attribute on the 2nd address to work with windows based programs (the cards work beautifully in OS X Address book, as it handles the inconstancies a bit better)

    example:

    {if street_2 != "" }{street_2}{/if}

    is output in plain text within the card as:

    {if suite 112 !=""}suite 112{/if}

    Some cards have users with a address that uses the street_2 field while others do not, and with no way to check this I am left with a extra line break on output.

    I have tried several different approaches within EE but I am a PHP n00b so I haven’t made much progress trying to solve it that way.

    Any help or insight is appreciated!

  • #2 / Jun 25, 2012 5:26pm

    ljanocha

    2 posts

    Nobody? Anything i can add to clarify the above example/issue?

  • #3 / Jun 27, 2012 1:16am

    Bhashkar Yadav

    727 posts

    Hi ljanocha,

    After reading reading your thread, i think you have issue with the tag

    {if street_2 != "" }{street_2}{/if}

    can you please do 2 more things :

    1) In the field setting of “street_2”, update the “Default Text Formatting for This Field” with “None”.

    2) Please be sure that PHP Parsing Stage of this template is “Output”.

    Also, please share you more findings on it.


    Best Regards,
    Bhashkar

  • #4 / Jun 27, 2012 10:24am

    ljanocha

    2 posts

    Hey thanks for the reply.

    Both of those suggestions are currently in place. ANY conditional is output as plain text not just the portion of the address field above. Trying to use the {count} variable for example also outputs plain text

    This has something to do with applying the PHP header, without some sort of preprocessor plugin I don’t think this is possible.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases