Add shape to zone progrmatically

Topics: Writing modules
Jun 12, 2012 at 10:37 AM

Hi, I am developing a module which when enabled will add a list of links to brands(I have created a view for this) in the FooterQuadFirst zone. To achieve this I created a ShapeTable Provider

 public class ShapeProvider : IShapeTableProvider
    {

        public void Discover(ShapeTableBuilder builder)
        {

            builder.Describe("Layout").OnDisplaying((context) =>
                {
                    var footer = context.Shape.FooterQuadFirst;
                    MvcHtmlString mvcHtml = new MvcHtmlString("<a href=''>Brands<a/>");

                    footer.Add(mvcHtml, "1");
                });
        }
    }

Now problem is how can I call my view in the ShapeProvider.  My view is located in Views/Parts/Brands.cshtml in the same module. Displaying mvchtml string like what I have done in the sample works great and shows the content in the FooterQuadFirst Zone. But I need to render view

thanx

Coordinator
Jun 12, 2012 at 5:49 PM

Instead of injecting a string, you can inject a Shape, and its template will be resolved dynamically.

builder.Describe("Layout")
                .OnCreated(created => {
                    var brands = created.New.Parts_Brands();
                    layout.FooterQuadFirst.Add(brands, 1);
                });

But actually it would be better to use a Driver, so that users can change the location using placement.info file, only if you want it to be customized.

You could also add it from the Layout file itself.

Jun 13, 2012 at 8:03 AM
Edited Jun 13, 2012 at 1:22 PM

Thanx sebastienros , It works as expected. One more thing, u said that I can add this from layout file. My view(template) is in different Module.Is it still possible to add this from Layout.

Coordinator
Jun 13, 2012 at 5:31 PM

From the Layout file, or any shape, type this:

Layout.FooterQuadFirst.Add(New.Parts_Brands(), "1")