Main Content

Create Hyperlinks for Embedded Web View Reports

This example shows how to create one-way and two-way hyperlinks between the document pane and the web view embedded in the report by using these methods from the slreportgen.webview.EmbeddedWebViewDocument class:

  • createDiagramTwoWayLink — Create a two-way link between a document location and a diagram in the embedded web view. Clicking a link in the document opens the target diagram in the web view. Clicking in the diagram scrolls the document pane to the target document location.

  • createElementTwoWayLink — Create a two-way link between a document location and a diagram element in the embedded web view. Clicking a link in the document opens the diagram that contains the model element and temporarily highlights the element. Clicking the element in the diagram scrolls the document pane to the target document location.

  • createDiagramLink — Create a link from the document to a diagram in the embedded web view.

  • createElementLink — Create a link from the document to an element of a block diagram in the embedded web view.

Create Class for Embedded Web View Report

Create a class named TwoWayLinkWebView that contains a fillcontent method that uses createDiagramTwoWayLink and createElementTwoWayLink to create two-way links between the document pane and the embedded web view in an embedded web view report.

classdef TwoWayLinkWebView < slreportgen.webview.EmbeddedWebViewDocument

    methods
        function wvdoc = TwoWayLinkWebView(reportPath,modelName)
            % Invoke the EmbeddedWebViewDocument constructor, which
            % saves the report path and model name for use by the fill
            % methods of the report.
            wvdoc@slreportgen.webview.EmbeddedWebViewDocument( ...
                reportPath,modelName);
        end

        function fillContent(wvdoc)
            % Fill the Content hole in the report template with design
            % variable information. Use DOM or Report API methods to
            % create, format, add, and append content to this report.

            [~, handles] = getExportDiagrams(wvdoc);

            n = numel(handles);
            for i = 1:n
                diagHandle = handles{i};
                diagHeading = createDiagramTwoWayLink(wvdoc, ...
                    diagHandle, ...
                    mlreportgen.dom.Heading(2, ...
                        get_param(diagHandle,"Name")));
                append(wvdoc,diagHeading);

                blockFinder = slreportgen.finder.BlockFinder( ...
                    diagHandle);

                while hasNext(blockFinder)
                    r = next(blockFinder);
                    elemHandle = r.Object;
                    elemHeading = createElementTwoWayLink(wvdoc, ...
                        elemHandle, ...
                        mlreportgen.dom.Heading(3, ...
                            get_param(elemHandle,"Name")));
                    append(wvdoc,elemHeading);
                end

            end
        end
    end
end

To create one-way links from the document panel to the embedded web view, replace createDiagramTwoWayLink with createDiagramLink and createElementTwoWayLink with createElementLink.

Create Embedded Web View Report

To create an embedded web view report for the sf_car model and test the two-way links in the report:

1. In the MATLAB Command Window, enter:

model_name = "sf_car";
load_system(model_name);
wvdoc = TwoWayLinkWebView("myReport",model_name);
open(wvdoc);
fill(wvdoc);
close(wvdoc);
rptview(wvdoc);

2. In the document pane, click a diagram name. For example, click Engine. The embedded web view displays the associated diagram.

3. In the embedded web view, in the explorer bar, click sf_car. The embedded web view displays the sf_car diagram and the document pane temporarily highlights the diagram name.

4. In the document pane, click an element name. For example, click Inputs. The embedded web view highlights the Inputs block.

5. In the embedded web view, double-click the Vehicle block. The document pane temporarily highlights the element name.

For other tasks to create your embedded web view generator, see:

To learn how to generate an embedded web view report, see Generate Embedded Web View Reports.

See Also

Topics