Forum

Thread tagged as: Question, Problem

Looking to output perch_content_custom into a PHP variable

Basically what I am trying to achieve is to output a single field into a PHP variable for later use within an emailed form. It is an event booking form and I want to output the events name within the emailed form.

Here is the current code I am using to try and get the field into the $event_name variable:

$event_name = perch_content_custom('Event', array(
                              'page' => '/events/event.php',
                              'template' => 'eventname.html',
                              'filter' => 'slug',
                              'match' => 'eq',
                              'value' => perch_get('s'),
                              'skip-template' => 'true',
                              'return-html' => 'true',
                            ));

The eventname.html simply contains the below, so I can pull a single field from the larger main template:

<perch:content id="eventName" type="text" />

I have been trying to get this working for a while now but to no avail. Currently when I receive the outputted email all I receive is the word "Array" instead of the templates content.

Any help would be brilliant, I am not massively familiar with PHP.

Jordan Mann

Jordan Mann 0 points

  • 4 years ago

Hi Jordan,

You need to add true onto your call:

$event_name = perch_content_custom('Event', array( 
'page' => '/events/event.php',
'template' => 'eventname.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'skip-template' => 'true',
'return-html' => 'true', 
), true);

Then you should be able to access your data like: $event_name[0]['field_id']

You don't need to create a new template to get one field

Hi Dexter,

Firstly, thank you so so much.

That works perfectly! Can't believe all it needed to add was ', true'.

Really appreciate your help!

Jordan