The way I would do it is to add the props you want to be able to edit on all pages to your baseModelClass with getters and setters that get from the startpage and set and save the startpage.
Then the built in @Html.PropertyFor(x => x.YourProp) should work.
Hi, Mark,
If you have a property on start page, say:
[Display(
GroupName = PropertyTabNames.SiteSettings,
Order = 160
)]
public virtual LinkItemCollection HelpMenu { get; set; }
Then, on the layout (or, in my case, in a partial view called Header.cshtml):
<div class="support-navigation" @Html.EditAttributes("HelpMenu")>
@Html.DisplayFor(m => m.Layout.HelpMenu)
</div>
So, EditAttributes("HelpMenu") is the important part. You should be able to edit the property on start page then.
Hope this helps,
Marija
Unfortunately I'm in Web Forms world at the moment, although would be nice to know if the MVC helpers work in the EPiServer Web Forms install and what I'd need to do to enable them.
Also for a lot of my stuff the property renderings don't give me enough control over the mark-up, which seem to have been a bit of a recurring theme for me so I'm interested in ways of working with EPiServer content that gives me more control over the UI.
I did initially think perhaps there might be some way of creating new content renders, as I know you can specify the page reference context for the web controls and, I believe the property web control passes off rendering to some sort of IContentRender from what I can tell - I actually started to look to see if I could find out what the property control does to render a LinkItemCollection in the hope I could add my own rendering but didn't have much luck.
After that I read about edit hints which seem more appropriate as it seems like it doesn't try to mangle your HTML as much (something which can be an issue with Web Forms in general), but have not seen a way to set a page reference for those.
Hi, Mark,
Unfortunately (or fortunately :)), I haven't been working much with webforms + epi7.
However, even in EPi 6, we haven't been using a lot of built-in EPiServer controls. Instead, we were either using a asp:Repeater or more commonly, a simple foreach. EPiServer controls are difficult to customize, so in the end, you spend more time trying to make them work the way you wanted than you would if you had written this from the scratch. It didn't pay off.
So, for LinkItemCollection, you can "foreach" items and write the HTML you want.
As for the editattributes, from what I see in Joel's post here: http://joelabrahamsson.com/episerver-editing-delight-challenge-web-forms-solution/, this might work for you:
<div ID="someControl" runat="server"></div>
someControl.ApplyEditAttributes<StartPage>(x => x.Links);
But, then you need to set InnerHtml for someControl from code behind.
As I said, I haven't been working any with webforms, but hope any of this helps.
@Mark: You might want to read my blog post about creating custom renderers for your properties: http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2012/10/Custom-renderers-for-properties/
You can basically control all html for the properties except for a wrapping element that is always created when working with Web Forms. For MVC, this element is only added when editing the content in the On-Page-Edit view.
I love you and want to have your babies!
That is so useful to know - I think in my case the usercontrol approach is likely to be the fastest for me, and although I'm sure there still a few bumps still in the road I'm going to try it right now! I'll let you know how I get along
Are topics like this covered in the documentation? I have been trying to reference the EPiServer 7.5 CMS and Framework documentation on the site but often don't find what I'm after (in fairness I'm still new so not sure what to sarch for half the time). I only ask as I was wondering what people consider the best resources of information for customising EPiServer, seems Linus' and Joel's blogs are right up there.
Wold of Web Forms. I feel for you but will still try and help ;)
First question. "Can you use the mvc helpers in web forms?"
Quick answer: Yes. Should you try and do it? I would say no. It's more complex to add support for it then what you get back. Read more on Razor in webforms.
Second question: Control over rendering props.
If you want more control over the rendering of the properties I would recommend creating custom props for the built in ones and then use these instead. In your custom property you could create your own PropertyControl and in that override the CreateDefaultControls and CreateEditControls. This way you get full control over what is rendered.
Quick example:
[PageDefinitionTypePlugIn]
public class MyCustomProp : EPiServer.Core.PropertyLongString
{.....
/// <summary>
/// Inherited. Creates an IPropertyControl that is used to display a user interface for the property.
/// </summary>
public override EPiServer.Core.IPropertyControl CreatePropertyControl()
{
//Create an instance of MyCustomPropertyControl which is used for displaying the property.
return new MyCustomPropertyControl();
}
.....}
/// <summary>
/// MyCustomPropertyControl implementation. Used for rendering MyCustomProperty property.
/// </summary>
public class MyCustomPropertyControl : EPiServer.Web.PropertyControls.PropertyDataControl{
{......
/// <summary>
/// Inherited. Create a controls for rendering the property in view mode.
/// </summary>
public override void CreateDefaultControls()
{
System.Web.UI.WebControls.Label l = new System.Web.UI.WebControls.Label();
l.Text = this.PropertyData.Value == null ? "[My custom property empty]" : this.PropertyData.Value as string;
Controls.Add(l);
}
/// <summary>
/// Inherited. Create a TextBox for rendering the property in edit mode.
/// </summary>
public override void CreateEditControls()
{
tb = new System.Web.UI.WebControls.TextBox();
this.ApplyControlAttributes(this.tb);
Controls.Add(tb);
this.tb.Text = this.ToString();
}
......}
More info found here.
Hope I made some sense. =)
Woa, I'm late to the party.. didn't see the other answers before mosting. Sorry for the spam
@Mark: It seems that the information in the SDK is very scarse. Thanks for the feedback and we will try to improve this since it's a central area.
Is there a way to do edit hints in master pages?
I'm unable to achieve the mark-up required in most cases with the inbuilt controls, but would like to make some of the common site chrome editable in the edit page. The actual field are stored on the start page node, although ideally would be editable regardless of what page.
I know this that properties support this but was unsure how the ApplyEditAttributes would work in the context of a page other than the current page.