Try our conversational search powered by Generative AI!

Hide/Show block property based on some other property in same block

ZZ
ZZ
Vote:
 

Hi,

Is it possible to hide/show block properties based on someother block, Lets say I have string property in a block and I want to hide it in a block based on another boolean property in the same block. Is that possible in CMS 12. ?

#306558
Aug 10, 2023 9:10
Vote:
 

Hi ZZ

Have you tried this? I hope this helps

https://gregwiechec.com/2018/03/hide-tabs-and-properties-in-edit-mode/

#306566
Aug 10, 2023 11:05
ZZ
Vote:
 

I have tried but it doesn't work. I am trying to use this link to create custom attribute https://docs.developers.optimizely.com/content-management-system/docs/writing-custom-attributes

but having difficulty to get the value of the property in CreateDisplayMetadata ()

public class HideFieldAttribute : ValidationAttribute, IDisplayMetadataProvider
    {
        private readonly string _fieldName;

        public HideFieldAttribute(string fieldName)
        {
            _fieldName = fieldName;
        }


        public void CreateDisplayMetadata(DisplayMetadataProviderContext context)
        {
            // get value of the property ??
            throw new NotImplementedException();
        }
    }
#306570
Edited, Aug 10, 2023 11:44
Vote:
 

Hi ZZ

I see you tried to roll out your own implementation with the dev doc, but your requirement is more complex and just implement a custom attribute would not be sufficient, because of this reason I suggested the package above.

P.S. The package I mentioned earlier does exact what you need. I used in other projects in the past, and worked like a charm.  In addition, it's open source, if you really keen to do your own implementation, check out the source to see what might be required.

#306571
Aug 10, 2023 12:24
ZZ
Vote:
 

Whats the name of the NuGet package and is this compatible with CMS 12.17.x ?

#306574
Aug 10, 2023 12:49
Vote:
 

Package is called Alloy.HideTabs --

It is compatible with CMS 12, yes.

#306580
Aug 10, 2023 18:56
ZZ - Aug 11, 2023 9:30
I tried but this doesn't work
Vote:
 

Another approach to showing/hiding properties based on another property's value can be found here:

https://www.codeart.dk/blog/2022/11/property-dependency-in-optimizely-episerver-cms-12/

#306581
Aug 10, 2023 18:57
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.