Forum

Thread tagged as: Question, Problem

display a field using perch_content_custom

You know, without PHP programming knowledge perch has a steep learning curve, at least for me it does which is very frustrating to get anything done.
Anyeay, I have a template that holds a shared region (contact info). I want to display the telephone number in another spot on the page. I tried using the content_custom tag, but I can't get the content to display. I've tried using several other things but I'm guessing and I can't get this to work, please help.

<?php perch_content_custom ('localPhone', array (
                        'template' => 'social.html',
                        'filter'=> 'localPhone', 
                        'match'=> 'eq',
                        'value'=>'localPhone'
                        ));
                 ?>

I want to return the value of this content:

 <perch:content id="localPhone" type="text" label="Local Phone Number" />

Here is the shared region template.

<div class="social-info">
                <ul class="social">
                    <li class="phone active">
                        <a href="#">
                            <i class="fa fa-phone"></i>
                            <span><perch:content id="localPhone" type="text" label="Local Phone Number" /></span>
                        </a>
                    </li>
                    <li class="mail">
                      <a href="mailto:<perch:content id="email" type="text" label="Email Address" required="true" />">
                            <i class="fa fa-envelope"></i>
                            <span>email</span>
                        </a>
                    </li>
                    <li class="facebook">
                        <a href="<perch:content id="facebook" type="text" label="Link to Facebook" required="true" />">
                            <i class="fa fa-facebook"></i>
                            <span>facebook</span>
                        </a>
                    </li>
                </ul> 
Kim Mazzola

Kim Mazzola 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

If you just want to display the content using a different template then all you would need to pass in is the template - you aren't filtering on anything.

In the docs it says:

"The perch_content_custom() function takes the region name and an array of options to enable you to manipulate the content."

Is your Region called localPhone? If not then you need to change that to the name of the Region.

Then in your array you pass in your template.

The docs are here, you don't need to know any PHP, but you will need to follow the docs. Guessing isn't likely to work! https://docs.grabaperch.com/docs/content/perch-content-custom/

I've read the docs several times. And, yes, guessing won't work, but what option do I have when the docs don't explain how to pass one field from a template onto another page? I need to understand the options and how to set up the perch_content_custom tag. The docs are not exactly helpful to figure out my exact situation. Since I don't know which options to choose, I am left trying your example and then substituting different options, hence guessing. ;-)

So, while I don't need to know PHP, I do need to understand the option choices and how to pass them successfully. That's really my question. Thanks!

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You need to pass in the name of the region as the first value.

You need to pass in a template that contains the field or fields you want to display in your array. That is all.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is the region called contact info ? If so:

<?php perch_content_custom('contact info', array(
    'template' => 'phone.html'
    ));
?>

and then the phone.html template would be the template you showed earlier:

<perch:content id="localPhone" type="text" label="Local Phone Number" />

So as Rachel says, you're just showing the region as normal. The template controls which fields and any HTML you want to output.

Perhaps it's me and the way I'm explaining it. For that, I apologize. I'm trying again to explain it another way.

I want to display the phone number (localPhone) from the social.html template in another area in a perch_layout. Using your suggestion of

<?php perch_content_custom('localPhone', array {
'template' => 'social.html'
));
?>

Nothing shows on the page.

If I use the following:

<?php perch_content_custom ('Social Media', array (
template' => 'social.html'
));
 ?>

All 3 items from the social.html template(see original post) in the list show. Now, the Social Media is all the content on the social.html template and it's being displayed in another area of the header on the page.

Perhaps if you see the page live it might give you a visual. Here is the live page as it is not without the adjustments.

In short, right above the 2 buttons for reservations and quotes I want to place the phone number that is also shown above that area in the black background -- small telephone icon. That area in the black is an unordered list (social.html) and it's a shared region that is part of a perch_layout and placed on a master page.

Hi Kim,

Like Drew mentioned, you should use:

<?php perch_content_custom ('Social Media', array (
'template' => 'phone.html'
));
 ?>

You then need to create a phone.html template (in addition to your social.html):

<perch:content id="localPhone" type="text" label="Local Phone Number" />

So, you are telling Perch to get information from the 'Social Media' region, but only output the content specified in the phone.html template, which in your case is just the phone number.

First, my apologies for not understanding that when you reuse the code you are not creating a 2nd instance of the phone number that would need to be edited separately. Your suggestion was exactly what I needed. I appreciate your patience and help.

Second, perhaps there is a way to make this better understood in your docs? Even using my situation as an example, I think it would supply any A-HA moment for a lot of users. Thank you.