Was this page helpful?

Create pages automatically

    Table of contents
    No headers

    (These instructions are from an OpenGarden.org forum posting by SteveB.)

    Version: 8.05 and higher

    The following will embed a button that will create a new page for you with a specified template. The benefit of this approach is that you can embed several different buttons to suit your needs instead of being limited that whatever pre-defined template type the parent page happens to have had.

    Code:
    {{wiki.create("Add product", _, "Product_Information")}}

    Wiki.Create now takes an optional title parameter. Since the purpose of wiki.create is to a create page, it will check if a page already exists with the proposed title and then append a number until a non-existing page title is found.

    For example:

    {{ wiki.create( path: "somewhere", template: "something", title: "My Page" ) }}

    Might result in a new page being opened with title "My Page (3)" if "My Page", "My Page (1)", and "My Page (2)" already exist.

    If you want to open the editor regardless if the page exists or not, use Wiki.Edit instead.

         

    The path can point to anywhere you like in the hiearchy, even to a page that doesn't yet exist. If the sub-page doesn't already exist, one is automatically created.

    To create a relative path, you'll need a bit of dekiscript magic, like this:

    Code:
    {{ wiki.create{ path: page.path .. '/sub-page/sub-sub-page', template: "something", title: "My Page" } }}

      

    To create a page with a date prefix (for example for Meetings pages that sort by date) you could do something like this:

    Click the New Page button below to create a new Meeting Minutes page using the Template:Meeting 
    
    {{ wiki.create{template: "Meeting", title: string.eval{code: "date.year(date.now)"}.."."..string.eval{code: "date.month(date.now)"}.."."..string.eval{code: "date.day(date.now)"}.." XYZ Team Meeting Minutes" } }}
    Was this page helpful?
    Tag page
    Viewing 6 of 6 comments: view all
    It's probably important that you differentiate between using args and parameters in this discussion, provide a link to that information or at least provide examples that work. Clearly this is just venting, but as a preacher of your system's values, it's frustrating when you are trying to help new users learn the system and they copy and paste example code on the more basic tutorials i.e. - {{ wiki.create( path: "somewhere", template: "something", title: "My Page" ) }} and it doesn't work. And should users, such as myself, be adding this type of information and correcting these pages when errors are found?
    Posted 08:52, 19 Aug 2009
    Using Template: Meeting, how would I change the default text for the button? I end up with a string problem
    {{ wiki.create{template: "Meeting", title: string.eval{code: "date.year(date.now)"}.."."..string.eval{code: "date.month(date.now)"}.."."..string.eval{code: "date.day(date.now)"}.." XYZ Team Meeting Minutes" } }}
    Posted 12:09, 23 Sep 2009
    I would like to be able to save the page immediately and open it in view mode instead
    Posted 04:53, 2 Aug 2011
    @gouwzee the methods outlined above will create a stub page. Would you want to simply view a stub page with no content? Wouldn't you rather write content for that page before viewing it?
    Posted 07:27, 2 Aug 2011
    No, it allows you to insert a template. I want to insert the template and save that. I guess in normal use it has very little added value. But I would make a call to a template that inserts dynamic page content
    Posted 10:29, 2 Aug 2011
    @gouwzee you should be able to do exactly that with the instructions above. create the template with dynamic content first. then point to it in your create button done in the fashion above. but you'll still have the problem that the page you create will need you to customize or programmatically add content or parameters to the page for it to be more meaningful.
    Posted 21:29, 2 Aug 2011
    Viewing 6 of 6 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by