Twig API

Everything Microscope stores is available to templates through craft.microscope. It is read-only by design — a template that could trigger a full site scan on a page view is a denial-of-service waiting to happen.

The quick version

{{ craft.microscope.score() }}            {# 0–100, or null if never scanned #}
{{ craft.microscope.grade() }}            {# A–F #}
{% for finding in craft.microscope.findings('php') %}
  {{ finding.title }} — {{ finding.severity }}
{% endfor %}
{{ craft.microscope.nextScheduledScan()|datetime }}

Methods

MethodReturns
score()The latest scan’s overall score, 0–100, or null if the site has never been scanned.
grade()AF for that score, or null.
latestScan()The most recent completed scan, or null.
scans(limit = 10)Recent scans, newest first.
scan(id)One scan with its full result, or null.
findings(category = null)Problems from the latest scan — passing findings excluded — optionally limited to one area.
history(limit = 30)Score history as { id, date, score } rows, for charting.
categories()The six area handles.
categoryLabel(category)The translated label for an area handle.
nextScheduledScan()When the next scheduled scan is due, or null if scheduling is off.

What a finding gives you

PropertyIs
severitycritical, warning, notice or pass.
categoryWhich of the six areas it belongs to.
checkHandleThe check that produced it.
title / summaryThe headline and a one-line explanation.
observed / expectedWhat was measured, and what it should be. Either may be null.
impact / remediationWhy it matters and how to fix it, as Markdown.
evidenceRows of detail for findings with several occurrences — templates, tables, fields.
occurrencesHow many times it was found.
docsUrlA link to further reading, where there is one.

impact and remediation are Markdown, so render them with Craft’s |md filter. For short strings inside a heading or a table cell, |md('gfm', true) renders inline without wrapping the result in a <p>.

Example: a status strip for an internal dashboard

{% set score = craft.microscope.score() %}

{% if score is not null %}
  
{{ score }}/100 — grade {{ craft.microscope.grade() }} {% set problems = craft.microscope.findings() %} {% if problems|length %}
    {% for finding in problems|slice(0, 5) %}
  • {{ finding.severity }} {{ finding.title }} {% if finding.observed %}{{ finding.observed }}{% endif %}
  • {% endfor %}
{% else %}

Nothing to look at.

{% endif %}

Next scan: {{ craft.microscope.nextScheduledScan()|datetime ?? 'not scheduled' }}

{% endif %}

Example: a sparkline of the score over time

{% set history = craft.microscope.history(20) %}

{% if history|length > 1 %}
  {% set max = 100 %}
  {% set step = 100 / (history|length - 1) %}
  
    
  
{% endif %}

The dashboard widget

If all you want is the score on Craft’s own dashboard, you don’t need any of this — Microscope ships a Score widget that shows the current score, grade and problem counts, with a link through to the latest report.