Including a Custom Date String That Automatically Updates on Build

This article will explain how to include a Custom Date String in your generated output. Creating a custom data string compared to using an existing Date Metadata item is useful if you wish to include specifically formatted dates into your documentation - such as removing the day from the string (which in some locales is included with %%LongDate%%)

While there isn't a built-in way to do this, but you can do it in a roundabout way using some custom Javascript.

1. Create a new text file in your project directory with a .js extension - e.g. customLongDate.js
2. Add that file to your project by right-clicking Other Files and selecting Add Existing Other File
3. Paste this text into the newly created Javascript file:

function customLongDate(originalDateString) {
     if (originalDateString.indexOf(",") != -1) {
         return originalDateString.substring(originalDateString.indexOf(",") + 1);
     } else {
         return originalDateString;
     }
}

Then, in your Project Settings (which can be found under the Project ribbon tab), you then need to add a new custom Project Property named CustomLongDate. Once created, you need to set the value of that property to:

<script>document.write(customLongDate("30 August 2018"));</script>

Now you are able to reference %%CustomLongDate%% anywhere in your content and in preview and output, it should appear without the leading day name.

You could also include this script file in the custom template and add the property to the template - but you would need to also add a reference to the script file in the template master.base.html file - it isn't enough just to add it to the template directory, you need to reference from the .html as well. 

You can find out how to create a custom template here:

https://innovasys.zendesk.com/hc/en-gb/articles/360000765543-Creating-A-Custom-Template

In this case, the relevant base template is the Classic topics template. If you do wish to use this inside your content file, you will also need to repeat this with a custom template for each Documentation type you are using (e.g. a .NET Documentation template). In order to do this, you need to:

 

  1. Place customLongDate.js in "C:\ProgramData\Innovasys\documentx2018\templates\TOPICS\CUSTOMTOPICSTEMPLATE\template\packages\custom\script"
  2. Reference the script file by editing master.base.html and add this just before the closing </body>:
    <script src="template\packages\custom\script\customLongDate.js"></script>
  3. In the Template Editor Properties page, add a new Template Property named CustomLongDate. Once created, set the default value of that property to:
    <script>document.write(customLongDate("30 August 2018"));</script>
    

 

 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.