Making a custom page type field only visible for certain templates

Tim G. asked on November 16, 2016 19:13

I have a custom page type where I want to add a new field which is only visible for a certain template. Is this possible? I thought it might be achievable using the 'Field advanced Settings > Visibility condition' but I'm not having any luck. It could just be my macro is not correct:

DocumentContext.CurrentTemplate.CodeName == "Template-CodeName"

Any help much appreciated.

Correct Answer

Jan Hermann answered on November 16, 2016 20:59

On the Form tab, please use this:

EditedObject.DocumentPageTemplate.CodeName=="somename"

2 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on November 16, 2016 19:36 (last edited on November 16, 2016 19:36)

I believe the DocumentContext's PageTemplate may not be available on the Form Tab, since a form tab's editing page doesn't have a template.

You have the right idea to use a macro to modify the Visibility condition, but you may need to do a lookup manually.

Documents[DocumentContext.NodeAliasPath].DocumentPageTemplate.CodeName

You'll have to see how you can get the NodeAliasPath, it may exist in the DocumentContext while the PageTemplate may not, otherwise you may need to create a custom macro that takes some Page identification (DocumentID perhaps) which is available and gets the value for you.

1 votesVote for this answer Mark as a Correct answer

Tim G. answered on November 16, 2016 20:59 (last edited on November 16, 2016 21:01)

Apologies - I posted this at the same time! I've used the below but I'll update as per your example ...

EditedObject.NodeTemplate == "Template-CodeName"

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on November 16, 2016 22:33 (last edited on November 16, 2016 22:36)

{%CurrentDocument.DocumentPageTemplate%} or {%CurrentDocument.DocumentPageTemplate.DisplayName%}

You can see all macro properties in system > macros > console

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on November 16, 2016 22:43

Unfortunately Peter, the CurrentDocument namespace is only available on the edit tab and within the live site. For the Form tab changes, you have to use EditedObject

1 votesVote for this answer Mark as a Correct answer

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