App.WorkWith().Page(myPage).Controls().add(MyControl,
"placeholder"
)
You are right, there is still no fluent api for that. We have plans to have this too :) Actually the fluent API is there but it is not visible at this level for this facade. You may add controls on page creation:
App.WorkWith()
.Page()
.CreateNew()
//create new page, working with Page facade
.Do(p => p.Name =
"Page1"
.Control()
//access to Control facade
//Create new Control, working with Control facade
.Do(c => c.Caption =
"My New Control in placeholder1"
.Do(c => c.PlaceHolder =
"Placeholder1"
.Done()
//Exit the Control facade, we are now back to Page facade
"My New Control in placeholder2"
//Exit the control facade
//will be called for the page facade
"Page2"
.SaveChanges();
Let me shed some light on the pages API. Actually the CreateNew(...) method is meant to be protected and I guess the example that Georgi wrote is a bit older. You should call CreateNewStandardPage() or CreateNewPageGroup() method to create new page. We are going to also introduce external page soon. The reason these are separate methods is because they return different facades. Although, in both cases we are working with page nodes both have very different characteristics, for example controls don't make sense for page groups. Here is the correct code:
.CreateNewStandardPage()
// returns standard page facade
.Do(pn =>
pn.Title =
"My Test Page"
;
.CheckOut()
// creates a draft vresion and locks the page
// the fluent API allows adding conrols only to drafts
.CreateNew(
new
Label() Text =
"My Test Label"
,
"Content"
.Publish()
Be aware that currently there is no easy way to control the order of the controls within a place holder with the API. This is due to the fact that the controls in a place holder can be mixed with controls coming from a chain of inherited page templates. Sitefinity allows you to insert controls between controls defined in a base template. Currently we rely on the UI layer to get information about the siblings of a control, but we are going to move this logic to the fluent API. I hope this can help you better understand our ideas. We are open for suggestions and now is the best time for discussing the API design. Greetings, Bob the Telerik team
That's correct.. We'll have this in the Dev. Manual by the end of the week! Sorry for the inconvenience.