Forum

Thread tagged as: Question, Problem

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
Tony Astley

Tony Astley 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you turn on debug, what does it output?

Added that and this appears at the foot of the admin area...

Debug Message - Perch 3.0.3
[1] SELECT u.*, r.* FROM perch3_users u, perch3_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='506f720bad50b02e927225df42f4e7f1' LIMIT 1
UPDATE perch3_users SET userHash='76e742c1c938b465432a39ed952fb6c3' WHERE userID='1'
[26] SELECT p.privKey FROM perch3_user_privileges p
[18] SELECT settingID, settingValue, userID FROM perch3_settings WHERE userID=1 OR userID=0 ORDER BY userID ASC
[6] SELECT itemValue FROM perch3_menu_items WHERE itemType='app'
Setting alert: Republishing is under way. (success)
[1] SELECT * FROM perch3_menu_items WHERE itemActive=1 AND itemType='menu' AND parentID=0 ORDER BY itemOrder ASC LIMIT 0, 1
[1] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=1 ORDER BY mi.itemOrder ASC
[1] SELECT itemTitle FROM perch3_menu_items WHERE itemType='app' AND itemValue='content' LIMIT 1
[1] SELECT * FROM perch3_menu_items WHERE itemActive=1 AND itemType='menu' AND parentID=0 ORDER BY itemOrder ASC LIMIT 1, 10
[2] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=2 ORDER BY mi.itemOrder ASC
File: /core/apps/content/modes/page.republish.post.php
[2] SELECT * FROM perch3_content_regions ORDER BY regionOrder ASC
[1] SELECT * FROM perch3_content_items c WHERE c.regionID=3 AND c.itemRev=1 ORDER BY c.itemOrder ASC
[1] Using template: /templates/content/_case_studies/_project_desc.html
UPDATE perch3_content_regions SET regionHTML='<h3>Resurfacing the ASDA Car Park in Swaffham.</h3>\r\n\r\n<p>We were the chosen contractor to resurface large areas of the ASDA Car Park in Swaffham. This project was undertaken over a period of 7 days. There were a few priorities during the project, one most notable being to avoid disrupting ASDA’s operations. Our project managers are well prepared to plan works in a way to avoid causing disruptions to our clients operations.</p>\r\n\r\n<p>The job also involved fitting a new length of fencing around the area of the car park, as you can see the fencing was in a very bad way before. Finally new kerbing was installed to reduce any obvious tripping hazards.</p>\r\n\r\n<p>We work closely with the ADSA Health and Safety team in order to keep their premises to a standard above expectations to reduce any accidental damage caused by any wear and tear.</p>', regionRev='1', regionLatestRev='1' WHERE regionID='3'
[1] SELECT MIN(itemRev) FROM perch3_content_items WHERE regionID=3
DELETE FROM perch3_content_index WHERE regionID=3 AND itemRev<0
[1] SELECT * FROM perch3_content_items WHERE regionID=3 AND itemRev=1 ORDER BY itemOrder ASC
DELETE FROM perch3_content_index WHERE regionID=3 AND itemRev=1
Using template: /templates/content/_case_studies/_project_desc.html
INSERT INTO perch3_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (1,3,3,1,'pageContent','Resurfacing the ASDA Car Park in Swaffham.\r\n\r\nWe were the chosen contractor to resurface large areas of the ASDA Car Park in Swaffham. This project was undertaken over a period of 7 days. There were a few priorities during the project, one most notable be'),(1,3,3,1,'_id',1),(1,3,3,1,'_order','1000')
[1] OPTIMIZE TABLE perch3_content_index
[4] SELECT * FROM perch3_content_items c WHERE c.regionID=4 AND c.itemRev=5 ORDER BY c.itemOrder ASC
[4] Using template: /templates/content/_case_studies/_project_images.html
UPDATE perch3_content_regions SET regionHTML='\n<ul>\n\n\n\n\n\n\n\n\n  \n\n<li>\n\n<img \n \n  sizes=\"33vw\" \n   \n  srcset=\"   \n  /perch/resources/asda-swaffham-before2-w480.png 480w,\n /perch/resources/asda-swaffham-before2-w960.png 960w,\n /perch/resources/asda-swaffham-before2-w1280.png 1280w,\n /perch/resources/asda-swaffham-before2-w2000.png 2000w\n  \" \n   \n  src=\"/perch/resources/asda-swaffham-before2-w960.png\" \n  \n  alt=\"Asda Swaffham Before 02\">\n\n</li>\n\n\n\n\n\n\n\n\n\n   \n\n<li>\n\n<img \n \n  sizes=\"33vw\" \n   \n  srcset=\"   \n  /perch/resources/asda-swaffham-after2-w480.jpg 480w,\n  /perch/resources/asda-swaffham-after2-w960.jpg 960w,\n  /perch/resources/asda-swaffham-after2-w1280.jpg 1280w,\n    /perch/resources/asda-swaffham-after2-w2000.jpg 2000w\n \" \n   \n  src=\"/perch/resources/asda-swaffham-after2-w960.jpg\" \n   \n  alt=\"Asda Swaffham After 02\">\n\n</li>\n\n\n\n\n\n\n\n\n\n    \n\n<li>\n\n<img \n \n  sizes=\"33vw\" \n   \n  srcset=\"   \n  /perch/resources/asda-swaffham-before-w480.png 480w,\n  /perch/resources/asda-swaffham-before-w960.png 960w,\n  /perch/resources/asda-swaffham-before-w1280.png 1280w,\n    /perch/resources/asda-swaffham-before-w2000.png 2000w\n \" \n   \n  src=\"/perch/resources/asda-swaffham-before-w960.png\" \n   \n  alt=\"Asda Swaffham Before 01\">\n\n</li>\n\n\n\n\n\n\n\n\n\n   \n\n<li>\n\n<img \n \n  sizes=\"33vw\" \n   \n  srcset=\"   \n  /perch/resources/asda-swaffham-after-w480.png 480w,\n   /perch/resources/asda-swaffham-after-w960.png 960w,\n   /perch/resources/asda-swaffham-after-w1280.png 1280w,\n /perch/resources/asda-swaffham-after-w2000.png 2000w\n  \" \n   \n  src=\"/perch/resources/asda-swaffham-after-w960.png\" \n    \n  alt=\"Asda Swaffham After 01\">\n\n</li>\n\n\n</ul>\n', regionRev='5', regionLatestRev='5' WHERE regionID='4'
[1] SELECT MIN(itemRev) FROM perch3_content_items WHERE regionID=4
DELETE FROM perch3_content_index WHERE regionID=4 AND itemRev<0
[4] SELECT * FROM perch3_content_items WHERE regionID=4 AND itemRev=5 ORDER BY itemOrder ASC
DELETE FROM perch3_content_index WHERE regionID=4 AND itemRev=5
Using template: /templates/content/_case_studies/_project_images.html
INSERT INTO perch3_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (5,4,3,5,'imageTitle','Asda Swaffham Before 02'),(5,4,3,5,'projectImage','/perch/resources/asda-swaffham-before2.png'),(5,4,3,5,'_id',5),(5,4,3,5,'_order','1000')
INSERT INTO perch3_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (4,4,3,5,'imageTitle','Asda Swaffham After 02'),(4,4,3,5,'projectImage','/perch/resources/asda-swaffham-after2.jpg'),(4,4,3,5,'_id',4),(4,4,3,5,'_order','1001')
INSERT INTO perch3_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (3,4,3,5,'imageTitle','Asda Swaffham Before 01'),(3,4,3,5,'projectImage','/perch/resources/asda-swaffham-before.png'),(3,4,3,5,'_id',3),(3,4,3,5,'_order','1002')
INSERT INTO perch3_content_index (itemID, regionID, pageID, itemRev, indexKey, indexValue) VALUES (2,4,3,5,'imageTitle','Asda Swaffham After 01'),(2,4,3,5,'projectImage','/perch/resources/asda-swaffham-after.png'),(2,4,3,5,'_id',2),(2,4,3,5,'_order','1003')
[1] OPTIMIZE TABLE perch3_content_index
Queries: 37
Memory: 3.393

This appears on the page attributes admin screen:

Debug Message - Perch 3.0.3
[1] SELECT u.*, r.* FROM perch3_users u, perch3_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='b96ead1ae870260d2000a13687e4d9dc' LIMIT 1
UPDATE perch3_users SET userHash='27ebf886eaa05831ef5ce21f4a06623a' WHERE userID='1'
[26] SELECT p.privKey FROM perch3_user_privileges p
[18] SELECT settingID, settingValue, userID FROM perch3_settings WHERE userID=1 OR userID=0 ORDER BY userID ASC
[6] SELECT itemValue FROM perch3_menu_items WHERE itemType='app'
[1] SELECT * FROM perch3_pages WHERE pageID=3 LIMIT 1
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/image.html
Using sub-template: /templates/pages/attributes/seo.html
[1] SELECT * FROM perch3_menu_items WHERE itemActive=1 AND itemType='menu' AND parentID=0 ORDER BY itemOrder ASC LIMIT 0, 1
[1] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=1 ORDER BY mi.itemOrder ASC
[1] SELECT itemTitle FROM perch3_menu_items WHERE itemType='app' AND itemValue='content' LIMIT 1
[1] SELECT * FROM perch3_menu_items WHERE itemActive=1 AND itemType='menu' AND parentID=0 ORDER BY itemOrder ASC LIMIT 1, 10
[2] SELECT mi.*, p.privKey FROM perch3_menu_items mi LEFT JOIN perch3_user_privileges p ON mi.privID=p.privID WHERE mi.itemActive=1 AND mi.parentID=2 ORDER BY mi.itemOrder ASC
File: /core/apps/content/modes/page.details.post.php
[1] SELECT * FROM perch3_resources WHERE resourceID='3' LIMIT 1
Array
(
    [w] => 480
    [h] => 361
    [target_w] => 480
    [target_h] => 
    [crop] => 
    [density] => 1
    [path] => asda-swaffham-after2-w480.jpg
    [size] => 63842
    [mime] => 
    [assetID] => 5
)
Queries: 13
Memory: 3.2619
Drew McLellan

Drew McLellan 2638 points
Perch Support

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?:

/perch/resources/asda-swaffham-after2-w480.jpg

Worked it out it shows the following:

Debug Message - Perch 3.0.3
[1] SELECT * FROM perch3_pages WHERE pagePath='/lloyds-pharmacy-virginia-water.php' LIMIT 1
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/image.html
Using sub-template: /templates/pages/attributes/seo.html
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/image.html
Using sub-template: /templates/pages/attributes/seo.html
[2] SELECT regionKey, regionHTML FROM perch3_content_regions WHERE regionPage='/lloyds-pharmacy-virginia-water.php' OR regionPage='*' ORDER BY regionPage DESC
Using template: /templates/pages/attributes/_project_cameo.html

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is templates/pages/attributes/_project_cameo.html your template?

Yes

<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>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great.

Any ideas on a resolution for this issue?

I guess this isn't possible then?

Drew McLellan

Drew McLellan 2638 points
Perch Support

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?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you get if you use perch_page_attributes() ?