Information Classification: External Restricted.
See https://www.chili-publish.com/security

Manipulating Text Frames

Similarly as for image frames, the best way of updating texts inside a CHILI document is by using Variable Data.

In some cases it can be useful to extract additional information from the actual text frames, though.

Extracting Text

To extract text, you can call the "GetText" function on a text frame. This takes two arguments:

  • formatted: boolean, to indicate whether you want plain text or a formatted TextFlow string
  • forDisplay: boolean. If true, and if the text frame contains variables, the displayTextFlow will be returned (otherwise the source/normal textFlow is returned)
var textFlow = editor.ExecuteFunction("document.selectedText.frame","GetText",true,true);
var plainText = editor.ExecuteFunction("document.selectedText.frame","GetText",false,true);

Importing Text

IMPORTANT NOTE: currently, hardly any validation is performed on imported text. And passing wrong values may in fact lead to a crash of the Editor. We advise you (until further notice) to be very careful with this functionality.

Most specifically, we'd advise you to consult us for specific use cases in the near future, while we work on additional functionalities and validation.
That being said, importing a textFlow into a text frame can be done using:

//OLD importTextFlow function
editor.ExecuteFunction("document.selectedText.frame","ImportTextFlow",newFlowXml);

 
//NEW allows the call to be added to the undo/redo stack. The previous call is still supported and when no undo/redo stack boolean value is provided it will be false by default.
editor.ExecuteFunction("document.selectedText.frame","ImportTextFlow",'newFlowXml','undo redo boolean(true/false)');
editorObject.ExecuteFunction("document.selectedFrame", 'ImportTextFlow', '<TextFlow><p fontFamily="Arial"><span>CHILI Publisher rocks!</span></p></TextFlow>', true);





One use case which we'll be working on ourselves in the near future, is using this to duplicate/edit existing flows. An example of this (for demonstration purposes only), might be exporting the textFlow of one frame (based on its tag), and importing that after some simple manipulation into another frame (frames respectively tagged "source_text_frame" and "target_text_frame"):

var origFlow = editor.ExecuteFunction("document.allFrames[source_text_frame]","GetText",true,true);

//HERE BE POTENTIAL DRAGONS:
var newFlowXml = origFlow.replace("old","NEW");

editor.ExecuteFunction("document.allFrames[target_text_frame]","ImportTextFlow",newFlowXml,true); //this text change is included in the undo/redo stack.

All information on this page must be treated as External Restricted, or more strict. https://www.chili-publish.com/security