Forum

Thread tagged as: Question

question on re-using content from part of template

I have a region on a page that uses a template that allows multiple items - this produces a listing of items with photo, description, details and a url link for each.

if I make that region 'shared' is it possible to just use one item of info from that template elsewhere on other pages? user wants to have a list of only the url links elsewhere on site.

many thanks

Charlie Elsey

Charlie Elsey 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Don't make the region shared- you'll be loading all the items for every page. Instead, use perch_content_custom() to get the item you need.

perch_content_custom('Region name', [
    'page' => '/page/the/region/is/on.php',
    'filter' => 'field_id_to_filter_by',
    'value' => 'value_to_look_for',
]);

thanks Drew that looks great

Thanks Drew - but do I NEED 'value'? not sure what I would put in there. from my initial question I want to display all URLs

template fragment in question

<a href="<perch:content id="venuelink" type="text" label="full page name to link to" html="false" required="true" />">View more details...</a>

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

You don't need to filter it, no. I thought that's what you were implying by saying you only wanted to display one item.

thanks. one final question on this... should I actually create an array, if I want all items for the particular field to show?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure I follow.

sorry I am not being clear.

from the initial page which displays a listing of several items, with details incl picture, description and url, I want to be able to display a list of all the urls for the items

if I use perch content custom I was asking if I would need to create an array to show the list of urls

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, use a template that only has the fields you want in it.

Sorry still cant get this to work

Hope to be clear - I have a region on one page that uses a template that allows multiple items and so outputs a list of venue names with photo, description and url to link to.

I want to re use the venuename and venuelink values on another page to produce just a list of hyperlinked venue names

I would use this template for that list

<perch:before> <ul > </perch:before> <li >

<a href="<perch:content id="venuelink" type="text" />"><perch:content id="venuename" type="text" /> </a> </li> <perch:after> </ul> </perch:after>

On the page in question nothing gets output using perch_content_custom as below

      <?php perch_content_custom ('cheltenham restaurants in brief', [ 
      'page' => '/cheltenham/cheltenham-restaurants.php',
        'template' =>'hospitality-link-in-list.html', 
        'filter' =>array ( 
        array (
        'filter' =>'venuelink',
        ),
        array (
        'filter' =>'venuename',
        ),
        )
    ]);
        ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think you want a filter then. Leave the filters alone - just use the reduced template.

ah hah - we got there in the end, thanks Drew, excellent as always!