Forum

Thread tagged as: Question

Editable text for perch:noresults?

Hi,

Does anyone know if it is possible to make the text you can put between <perch:noresults> editable?

My client has got one events page which uses the custom-listing-day.html template - if there are no forthcoming events they want to display a message - but this message will change, hence the need for it to be editable.

I have tried something like:

<?php
$result = perch_events_custom(array(
'filter'=>'eventDateTime',
'match'=>'gte',
'value'=>date('Y-m-d'),
'count'=>15,
'sort'=>'eventDateTime',
'sort-order'=>'desc',
template'=>'custom-listing-day.html'
));

if ($result) {
echo $result;
} else {
echo perch_content('Message');
}
?>  

Any ideas, or is it just not possible?!

Darren Neasham

Darren Neasham 1 points

  • 6 years ago

Darren. Do you have a region named "message"? If so then setup this region just as you would any region. Also I think you need to add "true" to your custom region for return to your $result variable, but this may not be true for custom regions.

But the simple answer here would be to add...

<perch:noresults>
...
<\perch:noresults>

To your template named "custom-listing-day.html" and add any perch:events tags you want displayed when there are no results.

EDIT: I was just thinking "message" region may never have been created yet if your custom region has always returned results. Have you verified this custom region outputs?

Drew McLellan

Drew McLellan 2638 points
Perch Support

PerchSystem::set_var('no_results_message', perch_content('Message', true'));

then in your template

<perch:noresults>
    <perch:events id="no_results_message" encode="false" />
<\perch:noresults>

Hi Robert,

Thanks for your reply. Yes, the 'Message' region is setup and outputs as any other custom region would.

I can get the message to display on the events page if I do a straightforward echo:

if ($result) {
echo $result;
} else {
echo perch_content('Message');
}

The trouble is, it displays the message whether there are events or not - which is probably something to do with the if statement - or the fact you can't physically do what I'm trying to do!

Can you put a call to an editable custom region within a template, e.g:

<perch:noresults>
<?php perch_content('Message'); ?>
<\perch:noresults>

I thought editable custom regions had to go on the main pages, rather than templates?

Ah, a crossover of replies - Drew has just responded - I'll try that one and let you know how I get on!

Hi Drew,

That hasn't worked - there are no forthcoming events and nothing is output where the no results message should be.

On the events page I've got:


<?php perch_events_custom(array( 'filter'=>'eventDateTime', 'match'=>'gte', 'value'=>date('Y-m-d'), 'count'=>15, 'sort'=>'eventDateTime', 'sort-order'=>'desc', 'template'=>'custom-listing-day.html' )); PerchSystem::set_var('no_events_message', perch_content('No Events Message', true)); ?>

In custom-listing-day.html template I've got:


<perch:noresults> <perch:events id="no_events_message" encode="false" /> </perch:noresults>

The 'No Events Message' region is setup and appears in the admin.

Am I missing something?

Solved it. PerchSystem::set_var should be before perch_events_custom:


<?php PerchSystem::set_var('no_events_message', perch_content('No Events Message', true)); perch_events_custom(array( 'filter'=>'eventDateTime', 'match'=>'gte', 'value'=>date('Y-m-d'), 'count'=>15, 'sort'=>'eventDateTime', 'sort-order'=>'desc', 'template'=>'custom-listing-day.html' )); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

That's it.