Try our conversational search powered by Generative AI!

Create 'for this block' assetfolder before creation of a block?


Hi Guys,

for a client I have a question.


So the client is on a page in the CMS. He can create several type of content blocks. So in a contentarea on the page he clicks on 'create a new block'. There are some required fields like adding an image etc. 

The problem:

What the client wants is to before he really creates the block (by clicking create) he wants to have the "for this block" asset folder available, so he can add his required image in that folder and add it to this block. 

Now he needs to add a dummy image, create the block for the "for this block" asset folder to appear, and then add his image to the folder and re-add it to the block. 

I'm not sure if there is a event i can attach to to create this folder before block creation...

Anyone has any ideas??


Jul 20, 2015 15:17


one solution could be to add custom validation so that you'll be able to skip the "required" screen, but you will not be able to publish the block until the property has been set. See this forum post:

Jul 20, 2015 15:54

Hi Per,

So what you are saying is that i remove the [required] attribute from the block, and create a custom validator (checking if the image is not empty), will cause it to publish the block initially, also creating the "for this block" ?

Jul 20, 2015 16:56

Yeah, that was what I was thinking. However, I see now that it will not work, as you will not get past the "required" screen anyway. I'm afraid you'll have to find another solution.  

Jul 21, 2015 7:16

I tried it... and it kinda works.. because property 'Image' is not required anymore. So when i create a block, it first tried to publish it, indeed creating the "for this block" folder, and then showing the error from the custom validator.  So this is a solution.

Only i have like 10 different kinda block types in my CMS, and all with different kind of 'required' fields. Its quite a hassle making a custom validators for all my block types :-)

Jul 21, 2015 8:28

How about creating a new attribute to handle the validation. That way you could just put the attribute on your image properties on your blocks:

    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
    public sealed class RequiredImage : ValidationAttribute
        public override bool IsValid(object value)
            return value != null;

        public override string FormatErrorMessage(string name)
            return "Add an image, dude!";

and then use it:

        public virtual ContentReference Image { get; set; }
Jul 21, 2015 8:36

ahhh.. now we're talking... this would be very elegant. I would just have to create 1 validator for each kinda property type and add the attribute on all the matching props... 

thanks Per... 

Jul 21, 2015 8:41

No problem!
You won't need one per property type if you are only going to check for null though. Just rename the attribute to something more generic, and make a generic error message.

Jul 21, 2015 8:47

is it possible to fetch the property name to add that in the errormessage?

Jul 21, 2015 8:49

The property name should be in the "name" parameter in FormatErrorMessage

Jul 21, 2015 8:53

yup... i tried it and you are right.. thanks again.

Jul 21, 2015 9:07
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.