Skip to content

Rendering Liquid in a Shortcode #3050

Answered by pdehaan
miklb asked this question in Q&A
Sep 15, 2023 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

eleventy.config.js

/**
 * @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig
 * @returns {ReturnType<import("@11ty/eleventy/src/defaultConfig")>}
 */
module.exports = function (eleventyConfig) {
  eleventyConfig.addShortcode('table', function(metric) {
    const tbody = [];
    for (const { city, data } of metric) {
      const amounts = data
        .map(({ amount }) => `<td>${ amount }</td>`)
        .join("");
      tbody.push(`<tr><td>${ city }</td>${ amounts }</tr>`);
    }

    return `<table>
      <thead>
        <tr>
          <th>City</th>
          <th>2012</th>
          <th>2013</th>
          <th>2014</th>
          <th>2015</th>
          <th>2016</th>

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@pdehaan
Comment options

pdehaan Sep 15, 2023
Collaborator

Answer selected by miklb
@miklb
Comment options

@pdehaan
Comment options

pdehaan Sep 16, 2023
Collaborator

@pdehaan
Comment options

pdehaan Sep 16, 2023
Collaborator

@miklb
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants