<miso-sources>

The articles that an answer cites, numbered so that each citation in the answer points to one of them:

<miso-ask>
  <miso-answer></miso-answer>
  <miso-sources></miso-sources>
</miso-ask>

Containers

ContainerDefault layoutFields from
<miso-ask>list: one article on each rowsource_fl on client.ui.asks
<miso-hybrid-search>horizontal: one row of small cardssource_fl on client.ui.hybridSearch
<miso-message-item>horizontal, under a Sources headingsource_fl on client.ui.conversation

You do not write <miso-message-item> yourself. <miso-messages> puts one in each message of the open thread, with a <miso-sources> in it.

To change the sources, call useLayouts on the workflow of the container, under the role sources. For Ask, use client.ui.asks, the context, so that follow-up answers get the change too.

Layouts

Give the layout type before the options:

client.ui.asks.useLayouts({
  sources: ["cards", { link: { open: false } }],
});
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

A new type keeps the other options of the default. The small cards of Hybrid Search and of the chat panel keep their compact markup when you change them to list.

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({
  sources: {
    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 number, the title and the date:

function renderArticle(layout, state, data, meta) {
  const { tagPair, escapeHtml } = layout.templates.helpers;
  const [openTag, closeTag] = tagPair(layout, data);
  const date = data.published_at
    ? new Date(data.published_at).toLocaleDateString("en-US", { dateStyle: "medium" })
    : "";
  return openTag +
    `<span class="miso-citation-index" data-index="${meta.index + 1}"></span>` +
    `<div class="my-source-title">${escapeHtml(data.title)}</div>` +
    `<div class="my-source-date">${date}</div>` +
    closeTag;
}

client.ui.asks.useLayouts({
  sources: { templates: { article: renderArticle } },
});

For Hybrid Search, set it on client.ui.hybridSearch. For the messages of the chat panel, set it on client.ui.conversation.

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 source_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.
  • Keep the miso-citation-index element with meta.index + 1. It draws the number that the citations in the answer point to.
  • Escape every value from the record with escapeHtml.
  • Style your own classes in your CSS.

Next