Forum

Thread tagged as: Question

Returning custom content from another page matched by user entered content

I have a list of venues that I want to return 'suites' that are associated with the venue page a user is currently on. Both pages have a region which sets the location a suite should be associated with.

perch_content_custom('suite excerpt content', array(
'page'=>'/suites/*',
'template'=>'venue-templates/venue_suites_listing.html',
'filter'=>'location',
'match'=>'eq',
'value'=> $locationName
));

So $locationName would need to be the location already entered by the admin for that page. i.e London which then checks if it matches whats been entered in the suite excerpt content region and then obviously shows all suites associated with that venue. I'm not sure how I set $locationName as perch_content('location') that the admin has entered though. I tried using perch_content('location',true) as I thought this would return the value entered but that doesn't work.

Can anyone help?

Jonathan Clift

Jonathan Clift 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

That should work

'value'=> perch_content('location', true),

provided that the region just returns the string you're wanting to filter by.

If that doesn't work, turn on debug and let us know what it outputs, and in what way it's not working.

It just seems to be returning an empty string. No errors. If I do a <perch: showall /> and hardcode the 'value' to one thats there I can see the value being returned.


SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='suite excerpt content' AND (regionPage LIKE '/suites/%' OR regionPage='*') SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=104 AND idx.itemRev=6)) AND ((idx.indexKey='location' AND idx.indexValue='')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC
Drew McLellan

Drew McLellan 2638 points
Perch Support

What does this output?

perch_content('location');

I've made some progress. "location" region wasn't outputting anything so I assumed it was somethign to do with my select box template. I updated it and copied it exactly from perch docs and that has at least started outputting some content. I can't see what the difference between my 2 templates though so I'm assuming it was some kind of white-space issue.

NEW

<perch:content id="location" type="select" label="Select Venue Name" 
options="Aintree|aintree, Carlisle|carlisle, Cheltenham|cheltenham, Epsom Downs|epsom, Exeter|exeter, Haydock Park|haydock, Huntingdon|huntingdon, Kempton|kempton, Markert Rasen|rasen, Newmarket|newmarket, Nottingham|nottingham, Sandown Park|sandown, Warwick|warwick, Wincanton|wincanton" allowempty="false" required="true" />

OLD

<perch:content id="location" type="select" label="Select Venue Name" options="Aintree|aintree, Carlisle|carlisle, Cheltenham|cheltenham, Epsom Downs|epsom, Exeter|exeter, Haydock Park|haydock, Huntingdon|huntingdon, Kempton Park|kempton, Market Rasen|rasen, Newmarket|newmarket, Nottingham|nottingham, Sandown Park|sandown, Warwick|warwick, Wincanton|wincanton" allowempty="false" required="true" suppress="true" />

Now it is outputting the location name but has break line characters in it, is this because it's coming from a select?


SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='suite excerpt content' AND (regionPage LIKE '/suites/%' OR regionPage='*') SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=104 AND idx.itemRev=13) OR (idx.regionID=184 AND idx.itemRev=3)) AND ((idx.indexKey='location' AND idx.indexValue='\n\naintree')) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do those appear in the HTML source of the select box?

Drew McLellan said:

Do those appear in the HTML source of the select box?

No doesn't show in the source

<option value="aintree" selected="selected">Aintree</option>

I've just recreated the select boxes again and seems to of resolved the issue this time. I'm not 100% sure what has actually solved the problem but I can only assume the way I'd entered the select options before created some white space within the values some how.

I did some testing copying the code from perch docs select box examples and they weren't outputting any additional characters.