Omni Systems, Inc.

  

Mif2Go User's Guide, Version 55

  

Valid HTML 4.01!

 

Made with Mif2Go

29 Working with FrameMaker markers > 29.7 Inserting code or text with markers > 29.7.6 Including code to be executed before a topic


29.7.6 Including code to be executed before a topic

Suppose you need to provide code that must be processed at the start of a topic, before anything has been written to the topic file; for example, variable content to be included in the <head> element of each HTML topic.

Because the same variable can be assigned a different value multiple times in a document, Mif2Go processes each assignment as it is encountered. Therefore, the assignment of a particular value to a variable must ordinarily precede the point where the variable is used. To get around this restriction, you can assign property TopicStartCode to a marker, to have the code executed before the topic starts.

For example, to provide a Help keyword in an XML section of the <head> element, you could assign property TopicStartCode to a custom marker:

[MarkerTypes]

F1Keyword = TopicStartCode

[MarkerTypeCodeBefore]

F1Keyword = <$$F1Key = "

[MarkerTypeCodeAfter]

F1Keyword = ">

[Inserts]

Head = <$KeyIndexF>

In macro <$KeyIndexF>, you would include code such as the following:

<Help:Keyword Index="F" Term="<$$F1Key>"/>

As another example, to include a variable number of keywords, each in its own <meta> tag:

[MarkerTypes]

MetaKeys = TopicStartCode

[MarkerTypeCodeBefore]

MetaKeys = <$$KeyCount++><$$Keywords[$$KeyCount] = "

[MarkerTypeCodeAfter]

MetaKeys= ">

[Inserts]

Head = <$AddKeywords>

[AddKeywords]

<$_repeat ($$KeyCount)>

<meta name="Help.Keywords" content="<$$Keywords[$$_count]>" />\n

<$_endrepeat><$$KeyCount=0>

[Macros]

OmitMacroReturns=Yes

[MacroVariables]

KeyCount=0

In this variation, you would use a counter ($$KeyCount) that starts at zero. As Mif2Go processes the MetaKeys markers for the start of the topic, the counter is incremented before each marker. The counter is used to index an array variable, into which the marker content is stored. Each succeeding MetaKeys marker gets its own slot in the array.

When Mif2Go is ready to write the <head> of the topic, the <$_repeat> loop (see §28.6.4.3 Using loop structures) writes as many <meta> tags as there were MetaKeys markers, each with the content from one marker, and the counter is set back to zero for the next file.



29 Working with FrameMaker markers > 29.7 Inserting code or text with markers > 29.7.6 Including code to be executed before a topic