creating pages on the fly

Topics: Developer Forum, User Forum
Apr 7, 2009 at 12:25 PM
Hi,

We had an existing site that we've added N2CMS to. We've created all the content items and changed the pages to be sub classes of these content items. Everything works really nicely. However, the client now wants to be able to create cms-enabled pages on the fly. However, I haven't found a way for N2 CMS to do this. When I create a new page from the N2 interface and choose one of the existing content items and assign a title and uri it just gives a 404 error. Is there a way to create pages in N2 that aren't mapped to pages that physically exist?

Thanks
Sidharth
Apr 7, 2009 at 2:14 PM
Creating a Content Item that is seen as, well, a Content Item to N2, but the same time doesn't exist physically in database is, indeed, possible, but not without some trickery. If this is exactly what you want, the idea is that you fool N2 by exposing such 'virtual' item via parent's .Children property. But I hardly doubt this is what you really need, or do you ? What's the problem to create a new item, save it, and use it as a normal item? What is the life cycle of such 'fictious' items ? What's your use case?

PS: if your're really curious (though, hope you're not), there's a code -- pay attention to GetFakeChildren() and how it is used. (I wonder to see it still works, anyway, i'm feel sorry for once writing that crap.)
Apr 7, 2009 at 3:01 PM

Hi Esteewhy,

Thanks for your reply. Well the reason why the client wants this is because they want to be able to create new content only pages but without contacting us every time and us having to do a full release. He wants the ability to add new pages whenever he requires.

I don’t think using the parent’s Children would work here, but I’ll check it out. Thanks.

So I guess, what the client really wants is to create pages on the fly from a generic content item. So he wants to be able to create a folder and add cms-enabled pages to it. Is that possible? Hmm, maybe the only way to get that to work is to change our site so that it handles 404 errors and then checks if the page exists in the n2 database. If it does then manually spit out the content. (That sounds horrible!)

Thanks

Sidharth

From: esteewhy [mailto:notifications@codeplex.com]
Sent: 07 April 2009 15:15
To: Sidharth Nayyar
Subject: Re: creating pages on the fly [n2:52540]

From: esteewhy

Creating a Content Item that is seen as, well, a Content Item to N2, but the same time doesn't exist physically in database is, indeed, possible, but not without some trickery. If this is exactly what you want, the idea is that you fool N2 by exposing such 'virtual' item via parent's .Children property. But I hardly doubt this is what you really need, or do you ? What's the problem to create a new item, save it, and use it as a normal item? What is the life cycle of such 'fictious' items ? What's your use case?

PS: if your're really curious (though, hope you're not), there's a code -- pay attention to GetFakeChildren() and how it is used. (I wonder to see it still works, anyway, i'm feel sorry for once writing that crap.)

Read the full discussion online.

To add a post to this discussion, reply to this email (n2@discussions.codeplex.com)

To start a new discussion for this project, email n2@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Coordinator
Apr 7, 2009 at 7:40 PM
How about a very simple solution? Creating an item with a very simple template:

UserCustomized.aspx:
<% @ Page . . . %>
<%= CurrentPage.CompleteContents %>

The user would have power to input whatever they wanted.

You could complete this with wiki-like snippets to input re-usable html:

<%= CurrentPage.CompleteContents.Replace("{pageheader}", LoadExternalContent("pageheader") %>

For extra power LoadExternalContent would look up content from another stored in a known location.
Apr 8, 2009 at 1:05 PM
Hi libardo,

Thanks for your reply. I'll check that.

Just another question. Our client has been able to create "new" pages based on existing content items that doesn't give 404 errors! So the scenario is this:

Root
+ Home Page/Start Page
      + MyCMSPage (points to MyCMSPage.aspx)

So there is a MyCMSPage.aspx that is in the root directory of the website - this physically present and is CMS-enabled. If the user tries to create another page based on the MyCMSPage's ContentItem, say MySecondCMSPage, and adds this to the HomePage it gives a 404 error. If however they add it to the Root Node then it works! Though the URL of the page is not MySecondCMSPage.aspx but instead MyCMSPage.aspx?page=20.

So I guess my question is the URI component not used to specify the page that this content item points to? It seems to if I create it in the Home Page/Start Page, but not if I add it to the Root Node.

Thanks
Sidharth
Coordinator
Apr 8, 2009 at 9:22 PM
Sorry I must have misunderstood your question. When you access an unknown address instead of throwing a 404 you display a page (that perhaps is dynamically created).

I think that's basically is what esteewhy is pointing to. Another example is the wiki where unknown urls result in an input form. There is also code.