I’ve set my header and footer to be snippets. I want to be able to have the user select or upload a logo image from the home page panel. The field is setup as follows in the home blueprint
headerlogo:
label: Header Logo
type: select
options: images
Now because the header is going to be used in my home, projects, a-project, etc. pages i can’t simply use echo $page->headerlogo(). The logo shows on my home and ‘projects’ page but not my individual project pages (i’m guessing because they’re buried deeper or something in the files).
How should i call ‘headerlogo’ in my header snippet so it works no matter where my header snippet is used?
I think it should be page('home')->headerlogo()
in this case.
However, instead of the home page, you could also use the site options to store/select that image (blueprint would be site/blueprints/site.yml
) and then use $site->headerlogo()
.
thank you for your quick response. i had tried doing it this way but had used $page(‘home’)->headerlogo(). How does dropping the $ affect the code?
by using:
<?php echo $site->contentURL(); ?>/1-home/<?php echo page('home')->headerlogo(); ?>
I am able to call my logo on all pages including the individual project pages!
Thanks you for help!
An easier way to find the right image would be:
<?php
$logo = page('home')->images()->find(page('home')->headerlogo());
?>
<img src="<?php echo $logo->url()" >
$page
by default refers to the current page (if not assigned another value) and does not accept any parameters.
Or even easier
$logo = page('home')->headerlogo()->toFile();
1 Like