Add a shape to layout.cshtml

Topics: Writing modules, Writing themes
Sep 5, 2012 at 10:37 PM

I think I need to add a shape to the model for layout.cshtml, but I'm not sure how to do it or even if it's the right way to go.

I want to use the tagservice from the tag module to display a number of tags on each page.

In layout.cshtml I added a shape template, like so:

WorkContext.Layout.Header.Add(New.CommonTags(), "8");

Problem is, I need to pass the tags into Commontags, but they are not available to me. 

This guy for instance ( ), added a field to the model in document.cshtml, but I'm nit sure how to accomplish that.

All help is greatly appreciated


Sep 6, 2012 at 10:30 AM

Hi, would this be a 'good' solution to the problem described above:



Sep 6, 2012 at 11:51 AM
Edited Sep 12, 2012 at 7:55 PM

Hi, I'll just continue rubberduckin' here.. ;-)

So I found out that a way to do it is using a IShapetableprovider. I found a similar solution here: This works perfectly. It's not really wizardy, you just hook it up! I would be interested in the probaly numerous other ways to do this?!

Sep 12, 2012 at 7:46 PM

Not sure what exactly you are trying to do, but I thought I'd mention that placement supports top-level zones now: "/AsideSecond:1"

Sep 12, 2012 at 8:03 PM
Edited Sep 12, 2012 at 8:37 PM

edited, replied to the wrong thread..

.. as for what I'm trying to:

I have a list of tags and I want to show them on my homepage. They are not part of a contentitem and can't be displayed using a widget.. I need to pass them from layout to another shape template.

I was wondering how I add to the layout model. IN the end I used the IShapeTableProvider the do it

Sep 12, 2012 at 9:24 PM
Edited Sep 12, 2012 at 9:25 PM

How can you have a list of tags that is not part of a content item? Is it your own custom table that has nothing to do with the built-in tags feature? How is this incompatible with displaying them in a widget? Can you be more specific about what exactly you need to put where? I'd advise creating your own shape and passing whatever you need in there, like this: var shape = New.SomeShapeName(SomeParameter: SomeValue);Layout.SomeZoneName.Add(shape); but I'm not sure that's what you're trying to do. If you need to get the tags from another content item, you could get the ContentManager from the WorkContext and then Get the item you want and then cast it to the tags part.

Sep 12, 2012 at 9:47 PM

I am using the build in tags feature, but it's more like a reporting function, showing the most used tags. So it's not rendering as part of a content item. It's somewhat like a tagcloud. 

i am using this (or something very similar) in my layout.cshtml. The SomeValue part is the problem here... 

var shape = New.SomeShapeName(SomeParameter: SomeValue);Layout.SomeZoneName.Add(shape);

my list of 'most used tags (aka somevalue)' needs to come from somewhere. So I decided to use an Ishapeprovider to add it when creating SomeShape and omit passing the model in the call. The call in layout.cshtml actually is:

WorkContext.Layout.Header.Add(New.SiteSearch(), "8");

The problem with using a widget and the zone system, is that the list of tags has to be rendered and displayed as part of the sitesearch template, it's not the complete template. I can put SiteSearch in a zone, but the tags need to be rendered within SiteSearch (if generates a lightbox that displays the tags)

thanx for helping me out by the way. Hope this clarifies my issue

Sep 12, 2012 at 10:45 PM

Oh, so you're trying to build a tag cloud. Why not use or copy the code in Vandelay.Industries?

Sep 13, 2012 at 8:33 AM
Edited Sep 13, 2012 at 8:36 AM

aaaaargh, crash when I just had everything formatted.

to summarize: it's not about the tagcloud, it's about getting the data (list of tags or tag shapes) into my template. I did look at the tagcloud btw. It all boils down to this:

provided i have this call in my layout.cshtml 

WorkContext.Layout.Header.Add(New.SiteSearch(), "8");

  • how do I get the model into layout.cshtml to pass along the SIteSearch
  • or how do I get the model directly into sitesearch

the second option is what I solved using an IShapeTableProvider, not sure if it's the best way to go (short version below)

	.OnCreated(created =>{
	var tags = _tagService.GetTags().ToList();
	created.Shape.PopularTags = tags;

btw: in this example GetTags gives me a list of TagRecords. Is there a way to create shapes from this list. buildDisplay needs IContent items..

Sep 13, 2012 at 8:00 PM

Not sure what model you're referring to. An IShapeTableProvider is a fine way to solve that problem.

You can create a shape from anywhere using an IShapeFactory.

Sep 13, 2012 at 9:24 PM

Ok, thanx for the feedback! Btw: by Model I just mean Model in the 'classic' MVC sense, to it would be the data or shapes I want the pass on the my .cshtml (in this example a list of tags)