Hi Anne,
Does this help?
Aniket
You could add a tag to the content area and a tag to a constructor in the controller, the controller can then render a different view for you.
@Html.PropertyFor(x => x.CurrentPage.MyContentArea, new {Tag = "FromAContentArea"})
Then you create two controllers:
[TemplateDescriptor( Tags = new[] { "FromAContentArea" }, TemplateTypeCategory = TemplateTypeCategories.MvcPartialController )] public class MyBlockController : BlockControllerBase<MyBlock> { //Render Content Area View } public class MyBlockController : BlockControllerBase<MyBlock> { //Render Standard View }
In our solution, for some reason, a specific block has been designed to only be able to dropped into an XHtmlString (TinyMCE). It might be due to the fact that this block is the FormContainerBlock, but nevertheless. Since putting blocks into XHtmlString properties gives you far less control of where your content is kept rather than putting them into ContentAreas, I'd like to convince my editors to start using the ContentAreas instead, using various other block types should they want to wrap the form in other content (which I suspect was the main reason we ended up with what we have.)
My main problem is that the CSS wrapper class used to control width of the content is controlled by whatever page the block is placed on. The FormContainerBlock by default of course has no formatting, but I've figured out the easy way of adding one by creating a custom view - but of course the problem is that adding a wrapper to the block in this view will result in the content of the block being much narrower when the block is dropped into a XHtmlString. (It might be worth mentioning it's the Foundation framework.)
Basically I'm looking for a (self running) way to use different templates when a block is rendered in a ContentArea as to when it's rendered as an XHtmlString by the block being dropped into the TinyMCE editor.
I know there are probably a lot of ways to solve this programmatically (I have read several posts and articles on UIDescriptors, looping through ContentAreas in controllers etc), and basically I'm looking for a neat, clean solution. As for client side, I could solve this with CSS but I don't want it, and using JS/ jQuery to remove the CSS classes is ugly. I'd rather add the wrappers to the custom block view and let it look oddly narrow when pulled into a XHtmlString property.
(For the record, with some restrictions, most blocks are allowed in most ContentAreas, and the ContentArea property is usually rendered in the view with a simple PropertyFor.)