How to generate dynamic background image for section?

Hi,

I’m not sure if this is a bug or just something that I’m not doing correctly. I’m trying to generate the background image for a section based on a meta field in my CPT. My CPT is called ‘Movies’ (from the TMDB API) and it has a meta field called backdrop_path. Now the data I get for the API for all movies only has the path, e.g. ‘/2vFuG6bWGyQUzYS9d69E5l85nIz.jpg’ so in order to generate the full URL this path needs to be prefixed with https://image.tmdb.org/t/p/original.

I set the background of a section for the Single Movie Post Template to be and Output PHP function.

<?php 

function backdrop_url( $backdrop_path ){
    $backdrop_url = 'https://image.tmdb.org/t/p/original' . $backdrop_path;
    return $backdrop_url;
}

I’m using JetEngine for my CPT and the meta field for the backdrop_path is called je_movies_backdrop_path

…but nothing happens. The image is not rendered. I tried this for a section, a container, block, and div element and in no case is the image being generated.

Strangely, if I use a text element and set the content to be dynamic using the Output PHP function and use the same expression {echo:backdrop_url('{je_movies_backdrop_path}')}, the text is rendered on the page and I can also set the text to link to this URL and it opens the backdrop image in a new tab confirming that this is a valid image.

Am I doing something wrong here or is this a bug?

Thank you.

1 Like