Content Store to CUE Print
The template
/storyline-to-cue-print/image/ccitext.xml
converts pseudo-storyline versions of
Content Store
image story elements to
CUE Print
image caption texts.
The part of the template that is responsible for converting the caption looks like this:
<cci:cutline_c> {% if storyline.elements and storyline.elements[0].fields.caption.value %} {{ storyline.elements[0].fields.caption.value }} {% elif summary and summary.fields.caption.value %} {{ summary.fields.caption.value }} {% else %} {{ content.fields.caption.value }} {% endif %} </cci:cutline_c>
The first if
statement specifies what to do if
the image storyline element contains a caption, and that is where we
want to support annotations. Replace the highlighted line with the
following:
{% with field=storyline.elements[0].fields.caption %} {% include "common/text-content.xml.j2" %} {% endwith %}
This assigns the content of the caption
field
(that is, a JSON object containing both text and markup operations)
to a variable called field
and passes it to an
included template, common/text-content.xml.j2
.
The next task is to create
common/text-content.xml.j2
. Create a
common
sub-folder in the image
folder and then create text-content.xml.j2
in the
new folder.
Open the new file in an editor the file and enter the following:
{% for op in field.ops recursive %} {% if op.name == "bold" %} <cci:bold>{{ loop(op.sub) }}</cci:bold> {% elif op.name == "" %} {{ op.text }} {% else %} {{ loop(op.sub) }} {% endif %} {% endfor %}
The first line ({% for op in field.ops recursive
%}
) starts a loop over the text "operations" in the field.
Remember that before executing the conversion templates,
CUE Zipline
converts the flat storyline to a hierarchical structure. In this
specific case, the field's annotations
property
has been converted to a hierarchy of operations
(ops
).
Initially, the line enumerates the top level list of text
operations, but the recursive
keyword specifies
that the loop can be executed recursively to process annotations
within annotations if necessary (a bold
annotation within an italic
annotation, for
example).
In the next line, the if
statement tests whether
the operation name is bold
, in which case a
CUE Print bold
tag (<cci:bold>
) is wrapped around the
operation, which is recursively resubmitted to the loop.
The next part of the if
statement handles the
actual text content:
{% elif op.name == "" %} {{ op.text }}
An operation with no name indicates plain text, so the template just
outputs the text directly, using {{ op.text }}
.
Finally, the last part of the if
statement
handles any annotations that are not to be converted to
CUE Print
tags:
{% else %} {{ loop(op.sub) }} {% endif %}
Since the operation isn't plain text, the template just resubmits it
to the loop, thereby ensuring that any sub-operations are handled
correctly. If, for example, the caption field supports
italic
annotations as well as
bold
, then any italic
operations will be "caught" by this else section. The
italic
operation will be ignored, and its content
passed back into the loop for processing. If the content is just
plain text, then it will be caught by the op.name ==
""
test. If the content includes any
bold
operations, then they will be caught and
handled by the op.name == "bold"
test, and so on.
If you actually want to convert italic
annotations and convert them to
CUE Print
tags, then you can do so by adding a test to the template:
{% elif op.name == "italic" %} <cci:italic>{{ loop(op.sub) }}</cci:italic>
In this way it is possible to catch all annotations supported by the source story element type and either convert them to corresponding tags in the target CUE Print text or ignore them and just pass on the content.
There is however, a third possibility – you may want strip out some annotations: not only ignore the annotation itself, but actually exclude the annotated content from the target. To do this you simply omit the instruction following the relevant operation test (that is, add a test with no corresponding action). To strip out all italic markup and content, for example, you could add the following line to the template:
{% elif op.name == "italic" %}