Skip to content

Allow setting a placeholder for an image #1877

Closed as not planned
Closed as not planned

Description

@dsosec

Description

Currently, the image()-function returns an error, if the specified image is not found. This makes it difficult to make templates, which include certain images, but which are only available later on.

The image function should include a "placeholder" property, which takes a content as parameter, which is rendered only if the image is not found at the specified path.

The syntax should be as follows:

image("path/to/image.png", width: 100%, placeholder: [Make sure to add an image before submission.])

Use Case

Users would be able to create documents and templates, where the document itself does not need to be modified to add an image to it. An image file only needs to be placed in the corresponding path for it to be rendered.

Otherwise, lacking an image file would mean the document fails to compile, rather than to display a placeholder.

Activity

  1. added
    feature request
    on Aug 7, 2023
  2. ondohotola commented on Aug 8, 2023

    @ondohotola

    I do something like

    #let display = false
    #align(center)[
       #figure(
          if (display) { image("image.jpg") }
          else { square(size: 5em, stroke: 2pt) },
          caption: if (display) {[Image]} else {[Image (obfuscated)]},
       ) <image>
    ]
  3. T0mstone commented on Aug 26, 2023

    @T0mstone
    Contributor

    If we really were to implement this, I would prefer a separate function that checks whether a file exists,
    with which you can then make your own wrapper to image.

    I'm not sure whether it's even a good idea tho. Making document output filesystem-dependent feels kind of wrong to me.

  4. added
    scripting
    on Sep 4, 2023
  5. laurmaedje commented on Jul 15, 2024

    @laurmaedje
    Member

    Closing in favor of #2025

  6. marked Support fallback images #7599 as a duplicate of this issue on Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestscripting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions