Automatic ID Generation for Topics

juhopvx
Posts: 3
Joined: Wed Dec 19, 2018 2:21 pm

Automatic ID Generation for Topics

Post by juhopvx » Wed Feb 20, 2019 4:04 pm

Hello,

I stumbled upon an unexpected (at least for me) behaviour when creating new .dita files.

Here is what I do:

1) File -> New...
2) In the "Choose a file template" dialog I choose my custom template which has the following structure:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="topic_${id}">
<title>${caret}</title>
...
</topic>
3) I enter a title for the topic ("test" in this case)
4) I check the "Save as" button and edit the path to my liking (filename: "test.dita")
5) I click "Create"

After this, the created file has an incorrect id. The result is the following:

Code: Select all

<topic id="test">
<title>test</title>
...
</topic>
So the id is set to be the same as the name of the file.

If I do the following:

1) File -> New...
2) In the "Choose a file template" dialog I choose my custom template again (same as last example)
3) I do NOT enter a title or check the "Save as" button
4) I click "Create"

Now, the file gets the correct id. Result being the following:

Code: Select all

<topic id="topic_vl4_trw_vgb">
<title/>
...
</topic>
So my question is: is this expected behavior? It certainly confused me.

sorin_carbunaru
Site Admin
Posts: 240
Joined: Mon May 09, 2016 9:37 am

Re: Automatic ID Generation for Topics

Post by sorin_carbunaru » Thu Feb 21, 2019 10:28 am

Hello,

If you go to Options > Preferences > DITA > New topics, you will see there's a Use the file name as the value of the root ID attribute check box that is selected by default. This check box controls what happens when you create and save a topic, but not when you create an untitled editor, and it is more powerful than the editor variables (such as ${id}) from the templates So, if you want to generate a random ID instead of the one based on the title, deselect the above-mentioned option.

All the best wishes,
Sorin Carbunaru
oXygen XML

Post Reply