Emergency

In urgent situations or outages, you can send a text message to our emergency line

Emergency line (text message only)

+45 29 70 15 95

Send a text message with the following information:

  • Your name and webshop
  • A description of the problem

Note: This service is only for critical situations where your webshop is down or has serious problems. For regular support, please use our normal support channels.

Images on landing pages

How to upload images to a landing page in Shoporama and show them correctly in your theme with getImages() and getSrc().

Reading time: about 10 minutes
Store owner Developer

You can attach one or more images to a landing page and show them in your theme. The images are stored as an array on the landing page, so you can show all of them, only the first one, or a specific selection. This article is aimed at developers and theme builders who work directly in Smarty templates, but store owners can also benefit from the sections about uploading and alt text.

Important: There is no method called $landing_page->getImage() in the singular. Always use getImages() in the plural, which returns an array, and pick out the first image if you only need one.

Upload images to a landing page

  1. Go to Landing pages in your admin
  2. Click Edit on the landing page you want to add images to
  3. Use the image field to upload one or more images by dragging them in or clicking to choose them from your computer
  4. Write a short description for each image. The description is used as alt text and helps both screen readers and Google
  5. Save the page

Show images in your theme

The landing page's images are retrieved with getImages(), which returns an array of image objects. Each image has the method getSrc(width, height, type, format, quality), which generates a URL for a scaled version of the image.

Show the first image (correct pattern)

<{$images = $landing_page->getImages()}>
<{if $images}>
  <{$image = $images[0]}>
  <img src="<{$image->getSrc(800, 400, 'fit')}>"
       alt="<{$image->getDescription()|escape}>">
<{/if}>

Show all images

<{foreach $landing_page->getImages() as $image}>
  <img src="<{$image->getSrc(800, 400, 'fit')}>"
       alt="<{$image->getDescription()|escape}>">
<{/foreach}>

Show only the first three images

<{foreach $landing_page->getImages() as $image name=img}>
  <{if $smarty.foreach.img.iteration <= 3}>
    <img src="<{$image->getSrc(600, 400, 'box')}>"
         alt="<{$image->getDescription()|escape}>">
  <{/if}>
<{/foreach}>

Show a hero image with a fixed crop and WebP

<{$images = $landing_page->getImages()}>
<{if $images}>
  <{$image = $images[0]}>
  <img src="<{$image->getSrc(1600, 700, 'box', 'webp')}>"
       alt="<{$image->getDescription()|escape}>"
       loading="eager">
<{/if}>

Parameters for getSrc()

  • width and height: the dimensions in pixels
  • type: fit (default) keeps the whole image within the given dimensions, box crops the image to the exact dimensions, and pad places the whole image on a white background in the exact dimensions without cropping
  • format (optional): jpg, png, or webp. If you leave it out, Shoporama chooses the best format
  • quality (optional): Shoporama always uses the store's own quality setting, so you can leave it out

Other useful image methods

  • getDescription(): the image description, use it as alt text
  • getFilename(): the image's original file name
  • getWidth() and getHeight(): the image's original dimensions in pixels
  • getHtmlSize(width, height, type): returns width and height attributes for the img tag, so the browser reserves space and the page does not shift its layout
  • getInline(width, height, type, format, quality): returns the image as base64 inline data, for example for preloads or CSS backgrounds without an extra request

Open Graph image for sharing

The Open Graph image is the image that is shown when the landing page is shared on Facebook, LinkedIn, or similar sites. It is a separate field and is retrieved with getOpenGraphImage(), which returns either an image object or false.

<{if $og = $landing_page->getOpenGraphImage()}>
  <meta property="og:image" content="<{$webshop->getUrl()|escape}><{$og->getSrc(1200, 630, 'box', 'jpg')}>">
<{/if}>

getSrc() returns an address without the domain, so the store's address must come first, or Facebook cannot fetch the image. If no part of the image may be cropped, use pad instead of box.

Tip: Use webp as the format for regular images to make them load faster. For Open Graph sharing, however, you should use jpg, as Facebook still handles it most reliably.

Best practices

  • Upload the image in at least the size you want to show it in. Shoporama scales down, not up
  • Add a description to the image in the admin. That gives you alt text and better SEO out of the box
  • Always wrap getImages() in an <{if}> check before you access [0]. Otherwise an empty array will cause an error
  • Use getHtmlSize to set the width and height attributes, so the page does not jump when the images load
  • Add loading="lazy" to images further down the page, but not to the first hero image

Frequently asked questions

I wrote $landing_page->getImage(), but the page breaks. Why?

Because the method does not exist. On landing pages, it is called getImages() in the plural and returns an array. If you only want to use one image, write $landing_page->getImages()[0] after checking that there is at least one.

How many images can I upload to a landing page?

There is no practical limit. But remember that each extra image is an extra file the customer has to download. On a typical landing page, 1 to 5 images are plenty. If you need to show a large gallery, consider lazy loading.

Which file formats can I upload?

Shoporama accepts JPG, PNG, GIF, and WebP. When the image is shown in the store, the system automatically converts it to the format and size you request in the theme, so you can safely upload your original high-quality image.

My image description is not shown as alt text. Why?

The description is not output in the HTML automatically. In your theme, you need to retrieve it with $image->getDescription()|escape and place it in the alt attribute of the img tag. Standard themes such as Delaware already do this for you.

Can I make a gallery or a lightbox?

Yes. Loop through getImages() and create both a thumbnail and a large version of the same image with two different getSrc() calls. Then combine them in a gallery script of your choice.

How do I make a full-page hero background from a landing page image?

Use, for example, getSrc(2000, 800, 'box', 'webp') and set the image as a background-image with an inline style on a section. Choose WebP to keep the file size down on mobile.

How do I know if an Open Graph image has been uploaded?

Call $landing_page->getOpenGraphImage(). If it returns false, no separate OG image has been set. Many then choose to fall back to the first regular image with getImages()[0].

Will large landing page images hurt my Google PageSpeed score?

Yes, if you serve full-resolution images to mobile devices. Use getSrc() to request a suitable size, set width and height on the img tag, and consider combining it with srcset for responsive images. See optimizing images for mobile.

Do I need to upload a new image for each size I want to show?

No. Upload one high-resolution version, for example 2000 pixels on the longest side, and Shoporama generates all the smaller versions you request in the theme. The scaled images are cached automatically, so they are only generated the first time.

Do you need help? Contact us at support@shoporama.dk.