Size efficient way to handle redundant text across cards

I suppose you’d include all the possible context paragraphs in your card template. Then you’d use some fields in each note that identifies which specific topic the note pertains to. The value in the note’s topic field would be either empty or “1”. The card template would then use conditional fields like this:

{{#Topic A}}
  Context paragraph for topic A
{{/Topic A}}

{{#Topic B}}
  Context paragraph for topic B
{{/Topic C}}

If there’s dozens of different topics, I’d use a single topic field, put the topic paragraphs into a .js file included in the collection.media folder and then use javascript to load the correct paragraph:

<p id="context-paragraph"></p>

<script>
    import("/_context_paragraphs.js").then(moduleObj => {
      const topicKey = "{{Topic}}";
      const contextParagraph = moduleObj.dict[topicKey];
      document.getElementById("context-paragraph").innerText = contextParagraph;
    })
  }

Contents of _context_paragraphs.js:

export const dict = {
  "Topic A": "Context paragraph for topic A",
  "Topic B": "Context paragraph for topic B",
}
1 Like