So assuming you have this new field IsPageX
added to all page types, you will have to set the visibility on the field itself on each page type this field is on. So on your IsPageX
field, scroll to the bottom of the field definition and find the visibility condition property and click "Edit" button. Click the Code tab at the top and click OK to the windows alert and enter the macro to only show the field at level 1 EditedObject.NodeLevel == 1
. This should resolve the first issue you're having troubles with.
For the second issue, getting that value in the master page as well as a custom webpart. You can use the code:
bool isPagex = ValidationHelper.GetBoolean(CurrentDocument.GetValue("IsPageX"), false);
If you place this code in the master page layout it will set the css class for you based on he IsPageX
field:
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (CurrentDocument != null)
{
bool isPagex = ValidationHelper.GetBoolean(CurrentDocument.GetValue("IsPageX"), false);
CMS.DocumentEngine.DocumentContext.CurrentBodyClass += (isPagex)? " class-1" : " class-2";
}
}
</script>