Images
Theme base has a set of image macros to help with rendering images with different configurations. All add the lazy attribute to image by default.
Responsive Picture#
A shorthand for outputting responsive picture elemets. This macro will calculate image transforms at our breakpoints based on the designSize variable which is configured in the macro itself (default 1440).
imageWidth{Number} REQUIRED The width of the image in a 1440px design.imageHeight{Number} optional The height of the image in a 1440px design.
Standard Image#
Outputs a standard img tag it takes the following options:
image{Craft image} REQUIRED A craft image objectclasses{String} Space separated list of classesstyles{String} Styles to write to the imagetransform{Craft transform} A craft transform objectalt{String} Content for the alt tag, will use image title if none supplied
Example with an image URL#
(Image URLs can't use transforms)
Example with a craft Image object#
Picture#
Outputs a picture tag with srcset using native lazy loading
image{Craft image} REQUIRED A craft image objectsrcsets{array} REQUIRED And array of srcsets to add using see belowclasses{String} Space separated list of classesstyles{String} Styles to write to the imagealt{String} Content for the alt tag, will use image title if none supplied
srcset syntax#
See defaultOptions in the code for the default srcsets.
Each srcset in srcsets should be an object with these options:
image{Craft image} An image for this srcset instead of the one defined in the main options object (above)transform{Craft transform} REQUIREDrule{string} REQUIRED A media query for this srcset. Can be empty string.
Example with Two different images#
In some cases we might want to have a different image on one breakpoint and another image at second breakpoint e.g. a different hero on mobile and desktop browsers.
imageOne is rendered (transformed to 500px wide) up to 599px.
Then imageTwo is rendered (transformed to 1920px wide) above 600px