---
schema_version: "1"
id: 3f2e49dcdae9a9476382f8d45a3f53714fce6dd1c067d6bcc22a75e8fe80f339
title: Considerations for Compiling and Rendering the Asset Model
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/guides/mc-apis/compiling-asset-model.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/compiling-asset-model.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 80700673d4e9125168a20cd5381f0461002626460776d95ddd2a9214ae110532
products:
  - Marketing Cloud Engagement APIs and Programmatic Languages
  - Marketing Cloud
---
# Considerations for Compiling and Rendering the Asset Model

Compile an asset in the context of a channel to return a flattened string of the asset content. You can use two compiling types:

- standard compiling
- rendering

Rendering accounts for superContent and design. Use rendering only for user representation and manipulation of content, as opposed to sending and publishing content.

## Standard Compiling

- IF an asset contains content:

  - FOR EACH placeholder block or slot in the content:

    - REPLACE the placeholder with the compiled string from the block or slot

  - RETURN replaced content

- ELSE:

  - IF an asset contains views:

    - IF an asset contains a view for the specified channel:

      - RETURN the compiled channel view

    - ELSE IF an asset contains an HTML view:

      - RETURN the compiled HTML view

    - ELSE:

      - RETURN empty string

## Rendering

- IF an asset contains content, design, or superContent:

  - IF an asset contains superContent and superContent isn't empty:

    - usedContent = superContent

  - ELSE IF an asset contains content and content isn't empty:

    - usedContent = content

  - ELSE IF an asset contains design and design isn't empty:

    - usedContent = design

  - ELSE:

    - RETURN empty string

  - FOR EACH placeholder block or slot in the content:

    - REPLACE the placeholder with the rendered string from the block or slot

  - RETURN replaced content

- ELSE:

  - IF an asset contains views:

    - IF an asset contains a view for the specified channel:

      - RETURN the rendered channel view

    - ELSE IF there is an HTML view:

      - RETURN the rendered HTML view

    - ELSE:

      - RETURN empty string

This JavaScript code example creates a full compiler.

```js
function getReferences(content, type) {
  var typeMarker = '<div data-type="' + type + '" data-key="';
  var splitContent = content.split(typeMarker);
  var results = [];
  if (splitContent.length > 1) {
    for (var i = 1; i < splitContent.length; i++) {
      var endTagMatches = splitContent[i].match(/(\/>)|(>[^<]*<\/div>)/i);
      var match = endTagMatches[0] || ">";
      results.push(typeMarker + splitContent[i].split(match)[0] + match);
    }
  }
  return results;
}

function compile(asset, channel) {
  asset = asset || {};
  var content = asset.superContent || asset.content || asset.design;
  if (content) {
    ["slot", "block"].forEach(function (type) {
      var references = getReferences(content, type);
      var types = type + "s";
      references.forEach(function (reference) {
        var refKey = reference.split('data-key="')[1].split('"')[0];
        if (asset[types] && asset[types][refKey]) {
          content = content.replace(reference, compile(asset[types][refKey]));
        } else {
          console.error("Bad Asset: referenced " + type + " does not exist: " + refKey);
        }
      });
    });
    return content;
  } else if (asset.views) {
    if (asset.views[channel]) {
      return compile(asset.views[channel], channel);
    } else if (asset.views.html) {
      return compile(asset.views.html, channel);
    }
  }
  return "";
}
```
