Skip to main content

How to programmatically read generated links of CMS_INPUT_DOM

Comments

2 comments

  • Zendesk API User
    Author: felix_reinhold - 5/21/2019 19:57

    Hi Andres,

    I usually do something like that:

    $CMS_SET(mytext)$$CMS_VALUE(st_thumbnail_body)$$CMS_END_SET$

    $CMS_SET(mytext,mytext.toString())$

    Now myText contains the generated content of the DOM.

    If you only need the links then you'd need to get the LinkDomNodes first. You could do sth. like this:

    $CMS_SET(ENUM_NODE_TYPE, class("de.espirit.firstspirit.access.editor.value.DomNodeType"))$

    $CMS_SET(domRoot, section.getFormData().get(language, "st_thumbnail_body").get().getRoot())$

    $CMS_FOR(node, domRoot.getChildren(true))$

         $CMS_IF(node.getNodeType() == ENUM_NODE_TYPE.LINK)$

              $CMS_SET(myLinkHTML)$$CMS_VALUE(node.getLink())$$CMS_END_SET$

              $CMS_SET(myLinkHTML, myLinkHTML.toString())$

              $CMS_SET(void, #global.logInfo(myLinkHTML))$

         $CMS_END_IF$

    $CMS_END_FOR$

    Replace the logging with the operations you want to perform with the links.

    best regards

    Felix

    0
  • Zendesk API User
    Author: agarcia - 5/22/2019 10:12

    Thanks felix.reinhold

    Your solution worked as a charm.

    I didn't know I had to traverse the DomNodes.

    Just for the record, in case anyone searches for this:

    Since I was working inside an script, after getting the Link object I had to access its fields to get the href and text:

    linkHref = node.getLink().getFormData().get(language, "lt_external_href"); // Depending on your link templates

    linkText = node.getLink().getFormData().get(language, "lt_external_text"); // Depending on your link templates

    0

Please sign in to leave a comment.