Hi all —
I have a main page with a bunch of subpages that get labeled with one of three possible tags (“yes”, “no” and “list”, in this example). The main page lists all the subpages, and when one hovers over the name of one of the subpages tagged “yes”, the background should be filled with the “coverimage” assigned to each specific subpage.
This is the field in the subpage blueprint:
fields:
coverimage:
label: Cover
type: image
I am using js. If I select an arbitrary background image to be displayed it works:
$(".yes").hover(
function(){
$('body').css('background-image', 'url(/assets/images/photo.jpg)');
$('body').css('background-size', 'cover');
$(".yes, .no, .list .arrows, .back").addClass("hide");
$(this).removeClass("hide");
},
function(){
$('body').css('background-image', 'none');
$(".yes, .no, .list, .arrows, .back").removeClass("hide");
},
);
However I have problems calling the child page and its featured photo.
$(".yes").hover(
function(){
$('body').css('background-image', '$img = $page->children()->coverimage()->toFile()');
$('body').css('background-size', 'cover');
$(".yes, .no, .list .arrows, .back").addClass("hide");
$(this).removeClass("hide");
},
function(){
$('body').css('background-image', 'none');
$(".yes, .no, .list, .arrows, .back").removeClass("hide");
},
);
What am I doing wrong? Thanks in advance!