Pages: 1
Print
Author Topic: InsertWithTemplate example  (Read 3502 times)
MrPaul
Member

Posts: 29


« on: December 19, 2013, 09:30:41 AM »

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

Code:
<Line><?xm-replace_text {Line}?></Line>

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:
<Template>
   <Name>Line</Name>
   <MiniTemplate><![CDATA[<Line><?xm-replace_text {Line}?></Line>]]></MiniTemplate>
</Template>

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.
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #1 on: December 19, 2013, 04:38:23 PM »

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: <xmetal install path>\Author\Rules\journalist.ctm
Logged
MrPaul
Member

Posts: 29


« Reply #2 on: December 23, 2013, 08:09:12 AM »

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:
<?xml version="1.0"?>
<!DOCTYPE DTDExtensions SYSTEM "ctm.dtd">
<DTDExtensions>
  <ElementPropertiesList></ElementPropertiesList>
   <Templates>
    <Template>
      <Name>Line</Name>
      <MiniTemplate>
        <![CDATA[<Line><?xm-replace_text {Line}?></Line>]]>
      </MiniTemplate>
    </Template>
  </Templates>
</DTDExtensions>

Then when calling:

Code:
Selection.InsertWithTemplate("Line")

It will insert this automatically:

Code:
<Line><?xm-replace_text {Line}?></Line>

It works!

Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #3 on: December 23, 2013, 04:37:25 PM »

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 from: 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().
« Last Edit: December 23, 2013, 04:40:28 PM by Derek Read » Logged
Pages: 1
Print
Jump to: