Skip to main content
https://github.com/codesyntax/cs.srcset/actions/workflows/plone-package.yml/badge.svg Latest Version Egg Status https://img.shields.io/pypi/pyversions/cs.srcset.svg?style=plastic:alt:Supported-PythonVersions License

cs.srcset

Backport of the srcset method added to the @@images view in plone.namedfile 7.1.0 to be able to use it in older Plone versions. It also includes an optimized @@image_helper view for Plone 6+ that uses catalog metadata to avoid N+1 performance issues in listings.

Features

  • Adds a view called @@images-srcset for older Plone versions (backport).

  • Adds a view called @@image_helper optimized for Plone 6+ catalog metadata.

Read more about responsive images and its use in the MDN documentation

Documentation

@@images-srcset

You should use this view like this

<img tal:define="images context/@@images-srcset;"
 tal:replace="structure python:images.srcset(
                             fieldname='image',
                             scale_in_src='huge',
                             sizes='(min-width: 570px) 550px,90vw',
                             css_class='mini w-100 h-100 responsive-3-2',
                             alt=context.Title(),
                             title=context.Title(),
                             loading='lazy')"
/>

The meaning of each parameter is the following:

  • fieldname: name of the field where the image is stored

  • scale_in_src: name of the scale that will be used to render the src attribute

  • sizes: the value of the sizes attribute in the output tag

  • css_class: CSS classes added to the img tag

  • additional attributes: any aditional attribute that will be rendered in the img tag, useful to add the title, alt, loading, fetchpriority, id, and other attributes.

@@image_helper

This view is designed for high-performance listings in Plone 6. It attempts to generate the <img> tag using only catalog metadata (image_scales attribute in brains), avoiding expensive getObject() calls. If metadata is missing, it gracefully falls back to the standard @@images view logic.

You should use this view like this

<tal:block tal:define="helper context/@@image_helper">
    <div tal:replace="structure python:helper.srcset(item, fieldname='image', sizes='25vw', css_class='my-img')" />
</tal:block>

Available methods:

  • srcset(item, fieldname='image', **kwargs): Returns a responsive <img> tag with the srcset attribute.

  • tag(item, fieldname='image', scale=None, **kwargs): Returns a fixed <img> tag (optionally for a specific scale).

Parameters:

  • item: Either a catalog brain (recommended for performance) or a Plone object.

  • fieldname: The name of the image field (default: image).

  • scale_in_src: (Only for the srcset method) The name of the scale to use for the src attribute (default: huge).

  • scale: (Only for the tag method) The name of the scale to use for the src.

  • **kwargs: Any other HTML attributes (alt, title, loading, css_class, etc.).

Note: Unlike standard Plone views, this helper does not provide default values for alt or loading attributes. Developers must provide them explicitly in the template if needed. However, it does automatically provide width and height based on the rendered scale to prevent layout shifts.

Installation

Install cs.srcset by adding it to your buildout:

[buildout]

...

eggs =
    cs.srcset

and then running bin/buildout

NOTE: You do not need to install the product in the Plone add-ons controlpanel, there is nothing to be installed.

Contribute

Support

If you are having issues, please let us know.

License

The project is licensed under the GPLv2.

Contributors

3.0.0 (2026-07-28)

Breaking changes:

  • Support Plone 6.2 only @erral (#3)

2.0.1 (2026-07-28)

Internal:

  • Format changelog @erral

Changelog

2.0 (unreleased)

Breaking changes

New features

1.2 (unreleased)

  • Nothing changed yet.

1.1 (2025-10-14)

  • Add default width and heigth attributes if none provided when using the srcset method [erral]

1.0 (2025-09-24)

  • Initial release. [codesyntax]

Metadata

Release files for cs.srcset 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs.srcset 3.0.0
File Size Uploaded Provenance Actions
cs_srcset-3.0.0.tar.gz 27.1 kB Without provenance Details for cs_srcset-3.0.0.tar.gz

Release files / cs_srcset-3.0.0.tar.gz

Download URL cs_srcset-3.0.0.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
72d7c5ef913ed17f79da6e726534dbbfa2e061b400615d4d81f621a226591927
BLAKE2b-256 checksum
How to use checksums
90c1fc8f203fd7d6f595af63b04f7adedce9b5c6c4f08bc5c19f1f3fae3c6e6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.1

Security for cs.srcset 3.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page