Page 1 of 1

Reusable Content with a variable

Posted: Thu Oct 21, 2021 11:54 am
by jakubm82
Hi!
I really need a help. I have created couple of reusable content and I want to use another one but with the variable which will change based on the document name. For example, "The following parameters of <variable = titleName> are available in the configuration menu".

How to setup the variable to automatically change the value to the topic name?

Thanks in advance!
Jakub

Re: Reusable Content with a variable

Posted: Thu Oct 21, 2021 12:21 pm
by Radu
Hi Jakub,

From what I understand I think you need to use the DITA 1.3 key scopes support:
https://blog.oxygenxml.com/keyscopes/keyscopesBlog.html

so use a keyref in the reusable topic and then refer to the topic in two places in the DITA Map, in each place under a different key scope where the key is defined to another value.

Regards,
Radu

Re: Reusable Content with a variable

Posted: Thu Oct 21, 2021 1:34 pm
by jakubm82
Hi Radu,

Thanks a million for your reply, but it is not exactly what I am looking for.
My team is using MadCap Flare which allows them to create snippets with variables. These variables works for example like that:
- documentation project is based on topics, each topic has a title. I am using DITA and Oxygen. Now, When a snippet is created, its content have reusable content but is also enhanced with a variable which automatically reads a title and replace the variable value with that title. Example:
<p>text text text <variable==post_name> text text text</p>
In output format, above example will look like that:
text text text Reausable Content with a variable text text text.

However if I put that snippet to a dirrerent topic, <variable==post_name> will be replaced with a dirrerent topic / post name.
I am not sure if my description is clear enough? Please let me know if more details is required.

To simplify, I don't want to use static keys, I want a key (code) that will be replaced dinamically based on the topic name.
a) I put snippet to topic ABC, variable is automatically displayed in output as ABC
b) I put snippet to topic CBA, variable is automatically displayed in output as CBA, and so on...

Re: Reusable Content with a variable

Posted: Fri Oct 22, 2021 7:59 am
by Radu
Hi,

There is no precise way to map this to DITA but you can achieve about the same result using key scopes.
Here's is a complete example I built and tested using Oxygen 24:

1) "main.ditamap" has the content:

Code: Select all

<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map>
    <title>Map</title>
  <topicref href="topic1.dita" keyscope="ks1">
    <keydef keys="topictitle">
      <topicmeta>
        <keywords>
          <keyword>T1</keyword>
        </keywords>
      </topicmeta>
    </keydef>
    <keydef keys="reusableComponent" href="reusableComponents.dita"/>
  </topicref>
  <topicref href="topic2.dita" keyscope="ks2">
    <keydef keys="topictitle">
      <topicmeta>
        <keywords>
          <keyword>T2</keyword>
        </keywords>
      </topicmeta>
    </keydef>
    <keydef keys="reusableComponent" href="reusableComponents.dita"/>
  </topicref>
</map>
2) "reusableComponents.dita" has the content:

Code: Select all

<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="reusableComponents">
    <title>Comp</title>
    <body>
      <p id="reusablePara">Hello <ph keyref="topictitle"/></p>
    </body>
</topic>
3) "topic1.dita" has the content:

Code: Select all

<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="t1">
  <title><ph keyref="topictitle"/></title>
    <body>
    <p conkeyref="reusableComponent/reusablePara"/>
    </body>
</topic>
4) "topic2.dita" has the content:

Code: Select all

<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="t2">
  <title><ph keyref="topictitle"/></title>
    <body>
      <p conkeyref="reusableComponent/reusablePara"/>
    </body>
</topic>

Regards,
Radu