Try our conversational search powered by Generative AI!

Page as Block rendering problem

Vote:
 

Hi,

I am working on a project where I'm supposed to have three different views for my "StandardPage as block", full width, 3/4 width and 1/4 width. The width of the block is determined of which contentarea the block is dropped into. If it's dropped into the "main contentarea" it's going to be 3/4, while if dropped in the bottom contentarea it should be full width. 

I'm using a ViewTemplateRegistrator and it looks like this (only made it for bottom and main at the moment):

          viewTemplateModelRegistrator.Add(typeof(StandardPage), new TemplateModel()
            {
                Name = "StandardPageBlock",
                Description = "",
                Path = "~/Views/Blocks/StandardPage/Index.cshtml",
                Tags = new []{ Tags.ContentAreaTags.Main }
            });

                    viewTemplateModelRegistrator.Add(typeof(StandardPage), new TemplateModel()
            {
                Name = "StandardPageBlockWide",
                Description = "",
                Path = "~/Views/Blocks/StandardPage/StandardPageWide.cshtml",
                Tags = new []{ Tags.ContentAreaTags.Footer},
                AvailableWithoutTag = false
            });

My view where the blocks are dropped looks like this:

@Html.PropertyFor(m => m.CurrentPage.BlockAreaMain, new { Tag = Tags.ContentAreaTags.Main })
// and
@Html.PropertyFor(m => m.CurrentPage.BlockAreaBottom, new { Tag = Tags.ContentAreaTags.Footer})

But when I'm dropping the block into the different contentareas, it only shows the first block (Index.cshtml). Any ideas why?

#140587
Oct 23, 2015 14:23
Vote:
 

Other content areas do not have any tags attached right? What exactly is "only first block is shown"? Do you mean that when block is dropped on other content areas that do not have any tags attached, "StandardPageBlock" template model (or ~/Views/Blocks/StandardPage/Index.cshtml) template is used? Or only 1st block in content area is rendered and rest of the dropped blocks are not visible?

#140610
Oct 25, 2015 8:35
Vote:
 

What I mean is, no matter what tag is used, the only view shown is Index.cshtml. So if I drop a StandardPage on MainContentArea(with tag), Index.cshtml is shown. And when I drop the same page in the BottomContentArea(with another tag), the same view is rendered, not the view tagged view.

EDIT:
I got this to work on my teaserblock earlier, but now it's the same problem. Same block rendering in different contentareas with different tags. With that said, no of my renderingstags are working.

#140615
Edited, Oct 26, 2015 7:41
Vote:
 

What changes if you set "AvailableWithoutTags=false" to both models? Algorithm for choosing templates for content types is something not so easy to grasp.. :)

#140619
Oct 26, 2015 9:16
Vote:
 

Then I get "The "StandardPage" can not be displayed".. I've read your blog on geta.no about what I'm trying to achieve, but I can't get it to work..

This is my complete TemplateRegistrator class:

 [ServiceConfiguration(typeof(IViewTemplateModelRegistrator))]
    public class ViewTemplateRegistrator : IViewTemplateModelRegistrator
    {
        #region Implementation of IViewTemplateModelRegistrator
        public void Register(TemplateModelCollection viewTemplateModelRegistrator)
        {

        
            #region Pagepartials
            viewTemplateModelRegistrator.Add(typeof(StandardPage), new TemplateModel()
            {
                Name = "StandardPageBlock",
                Description = "Displays pages that are of type StandardPage as a block in content areas",
                Path = "~/Views/Blocks/StandardPage/Index.cshtml",
                Tags = new []{ ContentAreaTags.Main },
                AvailableWithoutTag = false
            });

            viewTemplateModelRegistrator.Add(typeof(StandardPage), new TemplateModel()
            {
                Name = "StandardPageFooterBlock",
                Description = "",
                Tags = new[] { ContentAreaTags.Bottom },
                AvailableWithoutTag = false,
                Path = "~/Views/Blocks/StandardPage/StandardPageFooterBlock.cshtml",
            });

            #endregion
        }
        #endregion

And this is the HTML:

    <div class="container">
        <div class="row">
            <div class="col-md-12">
                @Html.PropertyFor(m => m.CurrentPage.BlockAreaMain, new { Tag = ContentAreaTags.Main })
            </div>     
        </div>
    </div>

    <div class="container-fluid">
        @Html.PropertyFor(m => m.CurrentPage.BlockAreaBottom, new { Tag = ContentAreaTags.Bottom })
    </div>

Am I missing something of importance..?

EDIT:
Created my own Tag class, it looks like this:

    public static class ContentAreaTags
    {
        public const string Main = "Main";
        public const string Footer = "Footer";
        public const string Right = "Right";
        public const string Bottom = "Bottom";
    }
#140622
Edited, Oct 26, 2015 10:03
Vote:
 

I have been looking into my problem and also re-created a simple project with the exact same pagetypes etc. In the new project it works, in the real project, it still doesn't. Even though it all looks the same..

#140637
Oct 26, 2015 13:24
Vote:
 

Do you have any event subscriptions to template resolving?

#140638
Oct 26, 2015 13:26
Vote:
 

No I don't think I do.

#140640
Oct 26, 2015 13:44
Vote:
 

When using my tags on the _Layout.cshtml view it works fine. Any ideas why I can't implement it on my "regular" pages? StartPage and so on.

#140641
Oct 26, 2015 14:08
Vote:
 

If you can, install please EPiServer Developer Tools and dump here all templates registered for content types.

#140643
Oct 26, 2015 14:34
Vote:
 

Is this v9?

#140663
Oct 26, 2015 21:27
Vote:
 

What do you mean with v9 Vladis?

#140668
Oct 27, 2015 8:25
Vote:
 

Asking about version of EPiServer?

#140669
Oct 27, 2015 8:59
Vote:
 

No, v8!

#140670
Oct 27, 2015 9:00
Vote:
 

It seems, that when I'm adding the "AvailableWithoutTag = false", it doesn't match my Contentarea-tag with my View-tag. Added it on another block and I instantly get "The "...Block" can not be displayed".. Although it works on my _Layout.cshtml.. Only difference between the layout and other pages is that I use a SettingsPage + LayoutModelFactory to bind it.

EDIT:

Again, I did a complete new project and installed my companies "template" which includes som basic features such as StartPage etc. This time, instead of re-creating everything, I simply copy-pasted the code I'm having trouble with in my real project, and it works in the new project but not in the real one.

#140671
Edited, Oct 27, 2015 9:48
Vote:
 

This is solved! 

A co-worker in my project had commented out some code a helperclass that was part of rendering in contentarea. This made it impossible to render page partials. Thank you for taking time to answer me Valdis!

#140691
Oct 27, 2015 20:19
Vote:
 

My pleasure to help :) I was really curious why it was not working on your setup. Even spin up alloy once again to repro.. :)

If needed - more insights about CA rendering pipeline you can find in my 3 series posts: http://blog.tech-fellow.net/

#140694
Oct 27, 2015 21:02
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.