zesty.io

Product

Use Cases

Integrations

Learn

Image Modifiers

Learn how to use Parsley image modifiers including resizing, and accessing image attributes such as image file name, title, and more.

All of the following Parsley calls represent a way to modify images. When the modification is first done the media service will return a temporary token URL which will resolve to the new image once the modification is complete. Afterwards the image will have its final static URL. This ensures page requests continue to resolve while images are being generated.

Looping through multiple images in a Media field

Users can upload multiple images to a single Media field as shown in the example below.

Multiple images in a single Media field

multiple-images-in-field-example


To access these images you'll need to loop through them with the following code:

In this example, images is the field's reference name.

media.is a keyword for defining the scope of the call. It is not a variable name or reference to a model.

Replace the{this.images}code with a reference to your model's specific field.

The order of the images is determined by the order that they appear in in the content model.

When wrapping this special each loop with an if-conditional be sure to use the media field's reference name to in the if-conditional. For example, if the reference name for your field is images and you're checking for an empty field then your if-conditional will look like this:

{{ if {this.images} != '' }}

.getImage(width, height, type)

Function takes a width, height, and an optional type (fit or crop) parameter and returns a URL of the resampled image. There are many ways to utilize this function. Fit is the default type and does not need to be explicitly declared. Crop type requires 2 parameters and explicit declaration. The list below shows examples of these calls. Learn how crop and fit work with this video.

.getImageFileName()

When called on an image reference, returns the image file name.

.getImageTitle()

When called on an image reference, returns the image title.

.getMediaURL()

Function does not take parameters and returns the original URL to that file. This is how to access files stored in media that are not images, such as PDFs and MP4s. You can also use this call to access the original file of an image that has not been optimized or altered by Zesty.io.

.gravatar(email)

Function takes a user's email and requests an image from the Gravatar API.

Responsive Images with srcset

In addition to Parsley you can use srcset to create responsive images. Learn more about srcset with this MDN article.

This is an example of how srcset can be used with Parsley:

Connect with Content Experts

Book a free 15-minute consultation with a content expert. Discuss your application, pain points and requirements. Understand how Zesty's lower total cost of ownership, features, functionality can elevate your business by creating extraordinary digital experiences.

Trusted By

zesty customer logo Sonyzesty customer logo Rocket Leaguezesty customer logo Singlifezesty customer logo Acornszesty customer logo Phoenix Sunszesty customer logo Wattpadzesty customer logo Corner Shopzesty customer logo Bjs

Enter your details to connect with a Content Expert

First Name

Last Name

Email

Phone (optional)

Company

Please tell us about your project (optional)

G2 MOMENTUM LEADER

zesty customer logo zesty customer logo zesty customer logo zesty customer logo