Forum

Thread tagged as: Question, Problem, Runway

Pre Select Region Type For Content Editor

Is it possible to pre-select the template for a given region on a template so the content editors don't have to? The goal is to make it simpler for content editors making a "New Page" to not have to remember what template name is what.

We're on Runway FYI.

Here's what I'm hoping it could be in an example:

Current Region call is:

<?php perch_content('Page Header'); ?>

Now can we pre select it's template like this?

<?php perch_content('Page Header','Header V1'); ?>

I'm sure my syntax is wrong, but you get the idea of what I'm looking for. Thoughts?

Leigh C

Leigh C 0 points

  • 4 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Leigh C

Leigh C 0 points

Sweet thanks!

Leigh C

Leigh C 0 points

So it works for normal pages as expected, but I'm integrating this into a page that uses a region to make a password for the page. This hides the content until the password is entered (crucial for this sensitive content we're posting). To make the password piece work, I'm using this solution from Simon - https://forum.grabaperch.com/forum/06-30-2016-password-protect-page-without-members-app

So basically I'm wrapping all the regions inside:

 <?php $password = perch_content('Password', true);  ?>

Then above all the content I want to hide:

   <?php print "";
              // If password is correct show restricted content
    if (isset($_POST["password"]) && ($_POST["password"]=="$password")) {
    ?>

Then the content creator makes a password specific to the page they are making, refreshes and the regions show up.

So using the perch_content_create in that special password region is blocking the rest of the regions.

I tried doing this to no avail:

        <?php $password = perch_content_create('Password', array(
            'template' => 'learn-simple-password.html',
            'multiple' => false,
            'edit-mode' => 'singlepage',
        ));
        ?>

Am I close?

Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_content_create() only creates the region. It doesn't return any content.

Use perch_content_create() and then follow it up with perch_content() or perch_content_custom()

Leigh C

Leigh C 0 points

Thanks Drew - can I have an example of that syntax from what I have now? Not sure where to "follow it up" with the perch_content tag:

        <?php $password = perch_content_create ('Password', array(
            'template' => 'password.html',
            'multiple' => false,
            'edit-mode' => 'singlepage',
        ));
        ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

perch_content_create('Password', array( 
'template' => 'password.html', 
'multiple' => false, 
'edit-mode' => 'singlepage', 
));

$password = perch_content('Password', true);
Leigh C

Leigh C 0 points

That did it - thanks!

Leigh C

Leigh C 0 points

Here's an extension of an issue I'm having now with the content create - other regions on the page are created, filled with content, but not showing any code. I flipped the master page to the old version (without content create) and it's working fine. So there must be something missing from this line to show the content, right?

        <?php perch_content_create('Page Header', array(
            'template' => 'page-header-with-branding.html',
            'multiple' => false,
            'edit-mode' => 'singlepage',
        ));

        ?>

Using this code for example, the Page Header shows up the edit mode with the right template. We can fill in content. But when the page loads, the code for that area is blank. Is it missing the perch_content part? If so, can you provide a full code chunk correcting it? I tried adding the call to it but it didn't work.

Drew McLellan

Drew McLellan 2638 points
Perch Support

This is exactly the same as above. You've created the region but then you're not using it. perch_content_create() creates a region only. It does not output anything.

Leigh C

Leigh C 0 points

That's what I thought and tried this, but it didn't work (as I mentioned):

<?php perch_content_create('Page Header', array(
'template' => 'page-header-with-branding.html',
'multiple' => false,
'edit-mode' => 'singlepage',
));

perch_content('Page Header', true);

?>

What's missing from my syntax here?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You are passing in true, so the content is being returned rather than output. This is explained in the documentation here https://docs.grabaperch.com/functions/content/perch-content/