Page 1 of 1

Add Attributes at File Creation

Posted: Thu Nov 30, 2017 2:04 am
by thedantanner
It would be very convenient (for me anyway) to be able to add certain attributes when creating new files in Oxygen. For example, all of our .XML and .ditamaps files include the attributes: product, revision, and language. We also use custom ID's for each file. Currently, we either have to enter these attributes manually, or generate the files with a tool we've set up in Access. I like having all of my tools in one place, so it would be cool if Oxygen allowed you to set these attributes from the NEW dialog box instead (or a subsequent dialog box that appears after the NEW dialog box).

Re: Add Attributes at File Creation

Posted: Thu Nov 30, 2017 10:20 am
by Radu
Hi,

You can define your own DITA new file templates:

http://blog.oxygenxml.com/2015/12/shari ... s-for.html

and the XML content of each new file template can contain inside Oxygen-specific editor variables which are automatically expanded by Oxygen when a file gets created:

https://www.oxygenxml.com/doc/versions/ ... ables.html

One of the useful editor variables is called ${ask} and it allows you to ask the end user for a certain value which will get expanded in place of the editor variable.

Regards,
Radu

Re: Add Attributes at File Creation

Posted: Thu Nov 30, 2017 8:06 pm
by thedantanner
This is a very helpful feature. Thanks for pointing me in the right direction.

I have created my custom extension which seems to be working exactly as the blog described.

The part where I'm getting in over my head is with the editor variables. I did follow the link you provided, but since I'm still pretty new to all of this, it was a little too broad for me to understand how to apply to my specific need. So perhaps you could offer a little guidance by explaining how to set up one particular customization?

For example... When I select file... new... and then select my "custom task", I give it a file name, chose the save directory, and press OK. At that point, if possible, I'd like Oxygen to ask me to enter the "product" attribute.

I appreciate your constant assistance.

Dan

Re: Add Attributes at File Creation

Posted: Mon Dec 04, 2017 11:31 am
by Radu
Hi Dan,

If you created in your custom framework a "customTask.dita" which has your custom DITA task contents, inside it you can use editor variables like for example:

Code: Select all

<!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
<task id="task_${id}">
<title>${caret}</title>
<shortdesc></shortdesc>
<prolog>
<author>${ask('Author name?', generic)}</author>
</prolog>
<taskbody>
<context>
<p></p>
</context>
<steps>
<step>
<cmd></cmd>
</step>
</steps>
</taskbody>
</task>
There are various editor variables in the task file template contents above and they will all get expanded, most of them automatically, for example the ${caret} will signify the initial location of the caret after the file is opened in Oxygen.
But the $ask editor variable will ask you a question, receive the answer from you and use that content to populate the template file.

Regards,
Radu