Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Different templates for block in ContentArea vs XHtmlString

Vote:
 

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.)

#179478
Edited, Jun 13, 2017 15:07
Vote:
 

Hi Anne,

Does this help?

https://www.epinova.no/en/blog/custom-rendering-of-content-in-xhtmlstring-areas/

Aniket

#179487
Jun 13, 2017 18:45
Vote:
 

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

}



#179506
Edited, Jun 14, 2017 11:45
Vote:
 

Thanks for your suggetions guys. Initially I wanted to solve this without using Tags, but I see now it should be part of the solution.

#179567
Edited, Jun 15, 2017 12:07
* 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.