Show/Hide elements depending on document type field?

Dcode warner asked on February 7, 2017 20:05

Is there another way i can write this so that I have have a checkbox or radio button in the document Type to either show or hide this element from appearing on the front end?

{% if (phone2.length > 0) { #%}

RESERVATIONS: {% phone2 %}

{% } else { #%} {% } #%}

Recent Answers


Dcode warner answered on February 7, 2017 20:06

<a {% phone2 %} " title="Call Us"> {% phone2 %}

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on February 7, 2017 20:27 (last edited on December 10, 2019 02:30)

Are you want to add a checkbox to decide to display the field or not? Or do you just want to check if the field is empty?

{% if( phone2 == ""){""}else{"RESERVATIONS: <a href='tel:" + phone2 +"' title='Call Us'>" + phone2 +"</a>" |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on February 7, 2017 20:29 (last edited on December 10, 2019 02:30)

If I understand correctly:

{% phone2.length > 0 ? phone2 : "<a" + phone2  + " title=\"Call Us\">" + phone2 +  "</a>"  @%}

You can as well show/hide web part on a page depending of document type by putting macro into visibility field of the web part:

{%CurrentDocument.ClassName == "MyDocumentType"|(identity)GlobalAdministrator%}

1 votesVote for this answer Mark as a Correct answer

Dcode warner answered on February 7, 2017 21:44

I want to add a checkbox to decide to display the field or not.

0 votesVote for this answer Mark as a Correct answer

Dcode warner answered on February 7, 2017 21:50

@Zachary Perry that script returns:

RESERVATIONS: True

Not the actual result

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on February 7, 2017 22:54 (last edited on March 24, 2018 12:15)

I misread your question. The Code I pasted was checking if Phone2 was empty and if not, displaying the value of Phone2, which it sounds like is your checbox.

I would go with something along the lines of Peter's suggestion. You add a bool field, then you can hide or unhide that field on the admin side by doing what he said and using depends on another field and visibility condition.

You would then change the transformation (sounds like that is what you are using) to something like this:

{% BoolField ? " RESERVATIONS: <a href='tel:" + FieldToDisplay + "'>" + FieldToDisplay + "</a>" : "" %}

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.