0 votes
in Rock by (13.1k points)
edited

Originally posted by Unknown

Warning: The solution below ignores security! Only use this if you are OK with by-passing security.

With security, use the default Email Communication URL:

/GetCommunication.ashx?c=[GUID]

One of our clients wanted to display a preview of their communication emails through their website.

Additionally, they wanted to publicly display emails without anyone having to log-in. By default, Rock does not allow this. You can, however, by-pass security with a lava entity. To do this, create a blank page layout, copy the code below, and paste it into an HTML block (with lava entities turned on):

Once set, then replace "[REPLACE-THIS-WITH-BASE-URL]" with their public domain name (otherwise all of the images will not load properly).

{%- assign commuincationGuid = PageParameter.CommunicationId -%}
{% if commuincationGuid != "" %}
{% communication where:'Guid == "{{ commuincationGuid }}"' securityenabled:'false' %}
{% assign comMsg = communication.Message %}
{% endcommunication %}
<style>
    #iframeMessage {
         width: 100%;
         height: 100%;
         min-height:2500px;
    }
</style>
<iframe id="iframeMessage"></iframe>
<script>
    function decode(str) {
        let txt = document.createElement("textarea");
        txt.innerHTML = str;
        return txt.value;
    }
    const getGeneratedPageURL = () => {
      const getBlobURL = (code, type) => {
        const blob = new Blob([code], { type })
        return URL.createObjectURL(blob)
      }
      const source = `<!DOCTYPE html>
        <html>
        <head>
          <base href="[REPLACE-THIS-WITH-BASE-URL]">
        </head>
        <body>
          {{ comMsg | Escape }}
        </body>
        </html>`
      let decodedStr = decode(source);
      return getBlobURL(decodedStr, 'text/html')
    }
    
    const url = getGeneratedPageURL()
    
    const iframe = document.querySelector('#iframeMessage')
    iframe.src = url
</script>
{% endif %}

Lastly, you will need to set the page route to capture the Guid. In this case, it was "communication/{CommunicationId}".

enter image description here

As a result, here is an example: https://stpatcc.org/communication/e47f7669-f812-4a8c-8ddc-54a726018e1a

1 Answer

0 votes
by (13.1k points)
edited
 
Best answer

Originally posted by Unknown

(Answered in the question ✅)

Welcome! Here you can ask questions and receive answers (hopefully) from other members of our team.
...