Skip to main content

An add-on for Plone

Project description

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

Features

It adds a view called @@images-srcset that has a single method called srcset to be able to create an img tag with the srcset and sizes attributes to render responsive images.

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

Documentation

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.

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

Changelog

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]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cs_srcset-1.1.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cs.srcset-1.1-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file cs_srcset-1.1.tar.gz.

File metadata

  • Download URL: cs_srcset-1.1.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for cs_srcset-1.1.tar.gz
Algorithm Hash digest
SHA256 68c49feb30139f2405f481e09846d7d9bd340f9ca11b42505338fbcdbf38a08b
MD5 6291ad6c933ef2bffcebde9792ba3d53
BLAKE2b-256 ced4a475d580a5682980e2976ffee54f20ddb051942a404ff1a385adb4e5ba89

See more details on using hashes here.

File details

Details for the file cs.srcset-1.1-py3-none-any.whl.

File metadata

  • Download URL: cs.srcset-1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for cs.srcset-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b04e69436830eec655c69d59a843ee6fddeaec74ecae484da3dde22cca5372b
MD5 7fe982d5cbcf83ca988f30e43c20aa5b
BLAKE2b-256 169b57070159f9593ba258a561e1369022f75cb88faf8d7727884e7c2c47caf9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page