0

Have strange issue checking contact type in \templates\CRM\Contact\Form\Contact.tpl

This code prints Organization / Society

{$contactType} / {$contactSubType} 

This code prints Organization / Society

{if $contactType eq 'Organization'}
   {$contactType} / {$contactSubType}
{/if}

But this one prints nothing

{if $contactSubType eq 'Society'}
       {$contactType} / {$contactSubType}
{/if}

And this one prints nothing

{if $contactType eq 'Organization' && $contactSubType eq 'Society'}
       {$contactType} / {$contactSubType}
{/if}

Shouldn't it "just" work? Or it's another bit of CiciCRM magic?

5
  • What are you trying to achieve? It might well be that modifying a template is not the best route to whatever you are trying to do (and it hardly ever is). Feb 9, 2016 at 8:26
  • 2
    In the DB contact_sub_type uses a special character to split multiple contact types. If this is being carried through to smarty then 'eq' might not produce a match (but the non-HTML character wouldn't be printed to screen). Can smarty check whether the $contactSubType just contains 'Society'? Feb 9, 2016 at 11:53
  • @AndrewWest : That's probably it, thanks a million for useful cue! Hope Smarty has kind of "eliminate special characters" built-in. Wish I could mark your comment as an answer.
    – yurg
    Feb 9, 2016 at 12:40
  • no probs! report back if that fixes it and I can add it as a proper answer. Feb 9, 2016 at 13:09
  • @AndrewWest : it definitely works after eliminating of U+001 special char added at the beginning at the end of contact sub-type name, thanks again for proper answer!
    – yurg
    Feb 9, 2016 at 15:21

3 Answers 3

2

(adding as an answer - see comment thread above)

In the DB, contact_sub_type uses a special character to split multiple contact types. If this is being carried through to smarty then 'eq' might not produce a match (but the non-HTML character wouldn't be printed to screen). Can smarty check whether the $contactSubType just contains 'Society'?

1

If isset contact ID ($contactId), you can use API in smarty like this:

        {crmAPI var='result' entity='Contact' action='get' id=$contactId}
        {foreach from=$result.values item=contact}
            <div>$contact.contact_type</div>
            {if $contact.contact_type eq 'Organization'}
                {* ... html ....*}
            {/if}
        {/foreach}
-1

If you want to hide Contact Details, the best way is explained in this post: How do I edit activity forms?

In my opinion the best way is to create a little extension and add a template with some jQuery code to hide the Contact Details. But you could give the css way a go too?

1
  • Thank you for valuable input, however, it doesn't answer the initial question, which is "why contact subtype check fails in smarty template, where contact type check works". Besides, as it was stated, elements should be hidden depending on contact subtype, which returns us to a starting point again..
    – yurg
    Feb 9, 2016 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.