Try our conversational search powered by Generative AI!

Blocks on page / local blocks?

Vote:
 

Do you know if it is possible in Episerver 7 to have local blocks, that are tied to a specific page and not visible to use on other pages on the site?

I would like to use blocks for creating pages in a flexible way - in our site this use would be more common than re-use of the same blocks (same content) on several pages.

For images it is possible to place them in the "page files" folder or in the "global files" folder - images placed in the "page files" folder will then be deleted when the page is deleted. I would like to be able to work in this way when organizing the blocks aswell. Is it possible?

#71344
May 16, 2013 10:14
Vote:
 

Hi, Elin,


One option you have is to use EPi blocks as "local blocks". When you are defining a block, you can set AvailableInEditMode to false, ie:

    [SiteContentType(
        GUID = "751FCE02-423B-4409-9CC5-744A37BAD015",
        AvailableInEditMode = false)]
    [SiteImageUrl]
    public class ImageBlock : SiteBlockData
    {
        [Display(
            GroupName = SystemTabNames.Content, 
            Order = 1)]
        [UIHint(UIHint.Image)]
        [Searchable(false)]
        public virtual Url ImageUrl { get; set; }

        [Display(
            GroupName = SystemTabNames.Content,
            Order = 2)]
        [CultureSpecific]
        public virtual string ImageAlt { get; set; }
    }

    

When you want it to be displayed on the page, you define a page property:

        [Display(
            GroupName = SystemTabNames.Content,
            Order = 300)]
        public virtual ImageBlock Image { get; set; }

    

So, you don't have a ContentArea, but an image block as a property.

This is a bit inflexible for your use, as I understand it, as it gives you exact number of properties on the page. However, it will have the same lifecycle as the page and will be present as a part of the page.

If you, however, need to add blocks to ContentArea only on one page, as you described, I don't think there is this "PageBlocks" functionality.

You can simulate it, by hooking to ContentCreated event and create a folder for each page and delete it on ContentDeleted by page name or so. It seems like a bit of overhead and also, as far as I can see you can't set access rights to the whole folder, only to each block, so you don't gain much and you still need to cover the pagename changes etc. So, basically, you help editors by creating their blocks folder inside a folder called, let's say, "Page blocks" and later cleaning it up for them by deleting this folder.

If you have a block that displays some page specific data, like price, name, etc and it's always on the same place, local block as described in the example is perfect, no need to overuse this new functionality of "shared blocks". If you don't have a specific structure, than I think you need to build up this functionality.

Hope this helps,

Marija

#71352
Edited, May 16, 2013 11:27
Vote:
 

Pagefiles are not deleted when you delete the page though. But they do inherit the page's access rights.

#71446
May 17, 2013 21:28
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.