Skip to main content
brickwork
GitHub Log in Get started
Display
Theme
Density
Direction
Brand

Documentation

Code

A labelled, scrollable code panel with optional copy enhancement.

All components Component Brickwork 4.3.1

Try it

Named Python snippet

Open full-page preview

A source panel with a language label.

views.py

Python

def component_view(request):
    return render(request, "example.html")
Use to present source snippets in documentation and editorial pages.

Use it

Working invocation

This code creates the configuration shown above. Copy the template and the required Python context together.

templates/your_app/component.html

Django template

{% include "brickwork/components/_code.html" with code=example_source filename=filename language=language id="component-example-view" %}

your_app/views.py

Python

context = {'example_source': 'def component_view(request):\n    return render(request, "example.html")', 'filename': 'views.py', 'language': 'Python'}

Guide

Add it to your project

  1. Include with plain source text or trusted, already-highlighted markup.
  2. Supply `filename` or `label` so the scrollable region is named.
  3. Supply a stable `id` if the filename repeats on a page.

View this component's source for the installed release

Options

Public API

Option Type Default Required Description
code str|SafeString Not set Yes Source text, or trusted highlighted markup. Constraint: No additional package-level validation is documented beyond this option's stated type and its role in the component.
language str Not set No Visible descriptive language label. Constraint: No additional package-level validation is documented beyond this option's stated type and its role in the component.
filename str Not set No Visible filename and default region name. Constraint: No additional package-level validation is documented beyond this option's stated type and its role in the component.
id str Not set No Stable id-safe identifier for repeated filenames. Constraint: Use a stable id-safe token of letters, digits, hyphens, or underscores; it must be unique on the page.
label str Not set No Region name when filename is absent. Constraint: Required if filename is omitted.
copyable bool False No Adds hidden-until-init copy control. Constraint: No additional package-level validation is documented beyond this option's stated type and its role in the component.

Behaviour

Accessibility and responsive behaviour

Accessibility
The overflow region is focusable and named; language is text rather than a colour signal; copy feedback is a polite live status.
Responsive
Long lines scroll horizontally at every viewport.
Without JavaScript
Source is selectable without JavaScript; the copy button only appears after enhancement.

Need help?

Troubleshooting

Contract check: supply ``label`` instead so the region is never nameless.

When `filename` is omitted, provide `label` so the code region and its copy control are not nameless.

Explore next

Used in examples

Documentation