Forum
Unable to Show Page Attribute with Template
Hello,
I have a page attribute assigned to a 'pageImage', I'm trying to pass the attribute into a page template with a custom template. The page template contains the ere fence to the page Attribute as follows:
<?php
perch_page_attribute('pageImage', array(
'template' => '_project_cameo.html'
));
?>
The '_project_cameo.html' template is stored in the attributes template directory:
site-folder/perch/templates/pages/attributes/_project_cameo.html
It looks like:
<perch:if exists="pageImage">
<div class="img <perch:pages id="pageID" type="hidden" /> clearfix">
<span>
<img src="/shim.gif" alt="">
</span>
</div>
<style type="text/css">
@media only screen {
.bg.portfolio<perch:pages id="pageID" type="hidden" /> {
background-image: url(<perch:pages type="image" id="pageImage" width="480" />);
}
}
@media only screen and (max-width: 1280px) {
.bg.portfolio<perch:pages id="pageID" type="hidden" /> {
background-image: url(<perch:pages type="image" id="pageImage" width="480" />);
}
}
@media only screen and (max-width: 960px) {
.bg.portfolio<perch:pages id="pageID" type="hidden" /> {
background-image: url(<perch:pages type="image" id="pageImage" width="480" />);
}
}
@media only screen and (max-width: 480px) {
.bg.portfolio<perch:pages id="pageID" type="hidden" /> {
background-image: url(<perch:pages type="image" id="pageImage" width="480" />);
}
}
@media only screen and (min-device-pixel-ratio: 2) {
.bg.portfolio<perch:pages id="pageID" type="hidden" /> {
background-image: url(<perch:pages type="image" id="pageImage" width="768" />);
}
}
@media only screen and (max-width: 1280px) and (min-device-pixel-ratio: 2) {
.bg.portfolio<perch:pages id="pageID" type="hidden" /> {
background-image: url(<perch:pages type="image" id="pageImage" width="768" />);
}
}
@media only screen and (max-width: 960px) and (min-device-pixel-ratio: 2) {
.bg.portfolio<perch:pages id="pageID" type="hidden" /> {
background-image: url(<perch:pages type="image" id="pageImage" width="768" />);
}
}
@media only screen and (max-width: 480px) and (min-device-pixel-ratio: 2) {
.bg.portfolio<perch:pages id="pageID" type="hidden" /> {
background-image: url(<perch:pages type="image" id="pageImage" width="768" />);
}
}
</style>
</perch:if>
The front end only ever shows the attribute, and ignores the template e.g.:
/perch/resources/project-image-01-w480.jpg
If you turn on debug, what does it output?
Added that and this appears at the foot of the admin area...
This appears on the page attributes admin screen:
Sorry, I need to the output from the page that isn't working. This output shows us what happens as the page is processed, so it's only any use if it's for the page that isn't working.
No worries Drew, but the page doesn't look any different with debug on or off?
the output simply shows the image path, should I be seeing something different?:
Worked it out it shows the following:
Is
templates/pages/attributes/_project_cameo.html
your template?Yes
Ok, great.
Any ideas on a resolution for this issue?
I guess this isn't possible then?
Is it not resolved? I thought you said that was your template.
If you're still having problems, what are they?
Hello Drew,
Apologies I'm not communicating my issue clearly. My issue is that despite me specifying a template to be used the page attribute only ever gets returned to the page as the path to the image, none of the html from the template is returned
When a very similar template is specified is used for navigation, it works perfectly.
Why is the system ignoring my request for that template to be used?
What do you get if you use
perch_page_attributes()
?