Forum

Thread tagged as: Question, Forum

Custom Content where the content has hyperlinks

Hi,

Apologies if this is in the documentation or forum somewhere but I couldn't find anything specific.

I'm pulling some regions from other pages into a listings page using custom content. This displays the info successfully. I would also like some of the content to be hyperlinked - in the example i created 'location-company-name' as a code block or text area and added a link but when it is brought into the listings page the tags are read as characters. Is there any way round this please?

 <?php
 perch_content_custom('location-region', array(
    'page'=>'/*',
    'template'=>'text-break.html',
)); 
?>

    </div>

 <div class="col-md-4 col-xs-4">
 <h2>Company</h2>
 <?php
 perch_content_custom('location-company-name', array(
    'page'=>'/*',
    'template'=>'text-break.html',
  )); 
  ?><br />
  </div>    

  <div class="col-md-4 col-xs-4">
  <h2>Tel</h2>
  <?php
  perch_content_custom('location-tel', array(
      'page'=>'/*',
      'template'=>'text-break.html',
  )); 
  ?><br />
John Robinson

John Robinson 0 points

  • 6 years ago
Michael Wilkinson

Michael Wilkinson 6 points
Registered Developer

Hi John

Do you mean that you added '<a>' and '<a/>' tags in the text boxes within Perch and it's outputting them as text themselves? If so, then I wouldn't put them in there at all. Instead, I would have your 'location-company-name' as a different template that wraps the HTML markup around the Perch tags. For example, your template could be:

<a href="<perch:content id="href-text" type="text" label="URL" required="true" title="true" />">
    <perch:content id="hyperlink-text" type="text" label="Hyperlink Text" required="true" title="true" />
</a>

Hope that makes sense.

Correct and just what I was looking for thanks, this worked great. I have a follow up question if I may?..

These regions from the other pages are feeding into my listings page and now have links on them.

I'm still creating these pages and they are showing on the listing page in the order that they are created. If i re-order pages in admin could/should this affect the sort order on the listing page?

hope you can help again, thnaks

Drew McLellan

Drew McLellan 2638 points
Perch Support

The content from the pages isn't ordered by page. You'll need to specify sort and sort-order options for perch_content_custom()

ah, thanks for pointing me in the right direction

Hi,

I'm having a bit of further difficulty now with sorting, hope you can help...

the pages i'm creating shows information on the listing page in three columns ( Location | Company Name | Telelphone Number)

I wanted to sort by company name alphabetically which worked, but of course the other details don't sort and don't adjust to match. I've also realised that resaving a page changes the order which would be a problem as the details don't line up.

Is there a way for a custome sort order? eg in the Location, Company Name and telephone regions of a particular page assign a number?

edit: think i can do it with a repeater region

The repeater region did work - i have been looking at this again and it would be nice to sort the information by the first column, is this possible.

This is the page with the listing https://www.dbtesting.co.uk/screenshot/Screenshot-2015-02-23-1.png

These are my pages - reordering doesn't make any difference to the page with the listing https://www.dbtesting.co.uk/screenshot/Screenshot-2015-02-23-2.png

this is the repeating region being pulled to the page with the listing https://www.dbtesting.co.uk/screenshot/Screenshot-2015-02-23-3.png

code in listing page..

                <?php
 perch_content_custom('location-company-name', array(
       'page'=>'/*',
      'template'=>'hyperlink-text-all.html',
    )); 
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to use the sort and sort-order options to sort the output.

they seem to kill it but i'll have another look if you say it's possible, thanks.

Sorry i'm still struggling. What should i use for 'sort' and 'sort-order' ? everything I try makes it blank. Here is my repeater content code...

<perch:repeater id="details" label="network-info" max="3">
    <perch:before><div class="location-table" style="width:100%; float:left; padding:10px 0;"></perch:before>

<a class="network-links" href="<perch:content id="href-text" type="text" label="URL" required="false" title="true" />">
    <perch:content id="hyperlink-text" type="text" label="Hyperlink Text" required="true" title="true" />
</a>

<perch:after>
</div>
</perch:after>
</perch:repeater>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show us what code you've got in the page? The options should include something like:

'sort' => 'id_you_want_to_sort_by',
'sort-order' => 'ASC',

it's as I mentioned before

                <?php
 perch_content_custom('location-company-name', array(
       'page'=>'/*',
      'template'=>'hyperlink-text-all.html',
    )); 
?>

This works. I can comment out

'template'=>'hyperlink-text-all.html',

and it still works. I thought that mattered so maybe it's set up wrong?

I have been trying different id's in the 'id_you_want_to_sort_by' part of sort => that look likely but all seem to break it.

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Please show me the full code that 'breaks' it.

Hi Drew. Sorry for delay, yes..

                <?php
 perch_content_custom('location-company-name', array(
       'page'=>'/*',
      'template'=>'hyperlink-text-all.html',
       'sort'=>'hyperlink-text',
        'sort-order'=>'ASC'
    )); 
?>

or..

                <?php
 perch_content_custom('location-company-name', array(
       'page'=>'/*',
      'template'=>'hyperlink-text-all.html',
       'sort'=>'href-text',
        'sort-order'=>'ASC'
    )); 
?>

or...

<?php
 perch_content_custom('location-company-name', array(
       'page'=>'/*',
      'template'=>'hyperlink-text-all.html',
       'sort'=>'hyperlink-text',
        'sort-order'=>'ASC'
    )); 
?>

thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do all your IDs have dashes in them?

Do all the items returned contain the field you're trying to sort on?

yes i've used dashes between words, they match what i'm putting in the sort field but could dashes be a problem?

based on my repeater region..

<perch:repeater id="details" label="network-info" max="3">
    <perch:before><div class="location-table" style="width:100%; float:left; padding:10px 0;"></perch:before>

<a class="network-links" href="<perch:content id="href-text" type="text" label="URL" required="false" title="true" />">
    <perch:content id="hyperlink-text" type="text" label="Hyperlink Text" required="true" title="true" />
</a>

<perch:after>
</div>
</perch:after>
</perch:repeater>

i thought the id should be 'hyperlink-text' ..

<?php
 perch_content_custom('location-company-name', array(
       'page'=>'/*',
      'template'=>'hyperlink-text-all.html',
       'sort'=>'hyperlink-text',
        'sort-order'=>'ASC'
    )); 
?>

but i've been trying a few id's to no avail.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Dashes could be a problem, but it's hard to say. They're not permitted in IDs, but whether they're the actual cause here I don't conclusively know.