<miso-related-resources>

More articles on the topic of the question. Ask shows them under the answer:

<miso-ask>
  <miso-answer></miso-answer>
  <miso-related-resources></miso-related-resources>
</miso-ask>

The answer does not cite these articles, so they have no numbers. For the articles it cites, use <miso-sources>.

Containers

ContainerDefault layoutFields from
<miso-ask>list: one article on each rowrelated_resource_fl on client.ui.asks

To change the list, call useLayouts on client.ui.asks, the context, under the role related_resources. Follow-up answers then get the change too.

Layouts

Give the layout type before the options:

client.ui.asks.useLayouts({
  related_resources: "carousel",
});
TypeWhat the reader seesClass
listOne article on each row.miso-list
cardsArticles side by side, in a grid.miso-cards
carouselOne row of articles, with buttons to scroll.miso-carousel
horizontalOne row of small cards.miso-horizontal

Options

Your options are merged over the defaults, so set only what you change.

OptionWhat it does
linkWhere the links open. { open: false } opens them in the same tab. Also takes target and rel.
classNameThe class of the layout, in place of the one in the table above.
templates.dateThe date format: options for toLocaleDateString with locale added, a locale string, or a function.
templates.articleThe markup of one article.

To change the date format, give templates.date the options of toLocaleDateString, with locale added:

client.ui.asks.useLayouts({
  related_resources: {
    templates: {
      date: { locale: "en-GB", year: "numeric", month: "long", day: "numeric" },
    },
  },
});

Write the markup of an article

Give your own function as the article template. It returns the HTML of one article. This one shows the cover image and the title:

function renderArticle(layout, state, data, meta) {
  const { tagPair, escapeHtml } = layout.templates.helpers;
  const [openTag, closeTag] = tagPair(layout, data);
  const image = data.cover_image
    ? `<img class="my-resource-image" src="${escapeHtml(data.cover_image)}" alt="">`
    : "";
  return openTag +
    image +
    `<div class="my-resource-title">${escapeHtml(data.title)}</div>` +
    closeTag;
}

client.ui.asks.useLayouts({
  related_resources: { templates: { article: renderArticle } },
});
ArgumentWhat it holds
layoutThe layout. layout.templates.helpers has tagPair and escapeHtml.
stateThe state of the whole list.
dataThe article. It holds only the fields that related_resource_fl asks for, with product_id and title always there.
metameta.index is the position of the article, counted from 0.
  • Start with tagPair. It returns the opening and closing tag of the item, which link to the article and record clicks on it.
  • Escape every value from the record with escapeHtml.
  • Style your own classes in your CSS.

Next