clone
Class: mlreportgen.dom.TemplateText
Namespace: mlreportgen.dom
Description
copies the specified template text.clonedTText
= clone(sourceTText
)
Note
To learn how to examine the source or updated template file directly, see Open Template Files.
Examples
To add additional content or holes, or to change the styling in an existing template, create a new TemplateDocumentPart
object to replace the existing TemplateDocumentPart
object. You can replace the relevant document part while the rest of the source template content remains unchanged.
Use tmplview
to display the template document part,"partToModify"
, in the source template. This document part currently contains the static text "Text in template document part"
followed by a template hole, "templateHole"
. In this example, you add additional text before and after the template hole by finding the part to modify, copying the original text and template hole, and appending your additional text.
tmplview("existingTemplate","html",OpenDocument="partToModify");
Import the DOM API namespace so you do not have to use fully qualified class names.
import mlreportgen.dom.*
Create a template by copying the existing template.
t = Template("updatedTemplate","html","existingTemplate"); open(t);
Find the part to modify in the document parts.
toModifyIdx = strcmp({t.TemplateDocumentParts.Name},"partToModify");
toModifyPart = t.TemplateDocumentParts(toModifyIdx);
Define a new template document part based on the document part.
newTemplateDocPart = TemplateDocumentPart("partToModify");
Copy the children of the original template document part into the new document part before and after the template hole. When your for
loop reaches the template hole, add the first line of new text, copy the template hole, and then add the second line of new text.
for child = toModifyPart.Children % If the child is a template hole if isa(child,"mlreportgen.dom.TemplateHole") switch child.HoleId case "templateHole" append(newTemplateDocPart,... Text("Text before template hole.")); append(newTemplateDocPart,TemplateHole(child.HoleId)); append(newTemplateDocPart,... Text("Content after template hole")); otherwise append(newTemplateDocPart,TemplateHole(child.HoleId)) end % If the child is not the template hole, copy the child to % the new document part else append(newTemplateDocPart,clone(child)); end end
Replace the part to modify with the new template document part.
t.TemplateDocumentParts(toModifyIdx) = newTemplateDocPart;
Close the template.
close(t);
Confirm the changes to the template document part by using tmplview
.
tmplview("updatedTemplate.htmtx",OpenDocument="partToModify");
To learn how to examine the source or updated template file directly, see Open Template Files.
Input Arguments
Template text to copy, specified as an
mlreportgen.dom.TemplateText
object.
Output Arguments
Copied template text, returned as an
mlreportgen.dom.TemplateText
object.
Version History
Introduced in R2024b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)