General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion InsertWithTemplate example

  • MrPaul

    InsertWithTemplate example

    Participants 2
    Replies 3
    Last Activity 8 years, 9 months ago

    I'm trying to call InsertWithTemplate to insert the following:

    [code][/code]

    In a previous application using an old version of xmetal (author v3 era), calling InsertWithTemplate(“Line”) used to insert the xml-replace_text processing instruction automatically. However its CTM file doesn't seem to have any special customizations for this element, so I'm not sure what needs to be done.

    Using XMAX v7, calling Selection.InsertWithTemplate(“Line”); does not insert the PI inside the node. What do I need to add to the .ctm file to make this work?

    I tried adding the following:

    [code][/code]

    But I'm not sure at what level in the ctm file it should go (and I cannot find the ctm.dtd file to know its structure) and whether or not this is even correct or necessary.

    Thank you for any insight.

    Reply

    Derek Read

    Reply to: InsertWithTemplate example

    If you are using XMetaL Developer this is very easy, as the CTM editor it includes guides you and will generate the CTM file for you.

    If you are not using XMetaL Developer and wish to try to create a CTM file then I think your best option would be to look at the Journalist sample that comes with XMetaL Author Essential and XMetaL Author Enterprise as it defines a number of mini-templates. The journalist.ctm file is located here: AuthorRulesjournalist.ctm

    Reply

    MrPaul

    Reply to: InsertWithTemplate example

    Thanks Derek. I already had a ctm file from the application we're migrating. It's just that there weren't any “Templates” in it so I'm still not sure why InsertWithTemplate was working in v3, but doesn't in xmax v7 unless I add the missing configuration in the ctm file. It works when I do that.

    For anyone else trying to accomplish the same thing, you can specify what to automatically insert when calling InsertWithTemplate when adding the following to the ctm file. For example:

    [code]
     
     
       
     
    [/code]

    Then when calling:

    [code]Selection.InsertWithTemplate(“Line”)[/code]

    It will insert this automatically:

    [code][/code]

    It works!

    Reply

    Derek Read

    Reply to: InsertWithTemplate example

    Not sure why it might have done that previously (I can't think of any way that it could have inserted mini-template content if there was none specified in the CTM). I don't think there's much point in installing XMetaL 3 and testing this since it is functioning according to the documentation in the current release:

    [quote=XMetaL Developer Programmers Guide]Inserts the specified element. If default content has been specified in the customization, this content is inserted with the element; if a script was specified, it is executed. This method can be used in ‘default content’ scripts to insert other elements and their default content. This method is not namespace aware.

    In this context “customization” = CTM settings.

    Perhaps you have confused it with another API such as InsertElementWithRequired().

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support