Forum

Thread tagged as: Question

How do I specify templates for regions?

I know you can do it using perch_content_custom() easily. But, is there a way to specify the template that a region should use with perch_content()?

Say I create a region that is very specific. It needs an image, title, text, a link and specific markup.

When I was watching the Perch videos, the narrator always seemed to create specific templates and then when they went to edit the region on the dashboard, they had to select a template. To me this seems odd. Why not specify which template is needed?

Is there a way to ensure that the client can only use the template that I made for that region?

Eric Mobley

Eric Mobley 0 points

  • 6 years ago

Hi Eric,

It's indeed the way to go when you use perch_content(). You create your template, you refresh your page, then you select the template name from the dropdown list in the dashboard.

For ensuring the client doesn't change the template, you can simply create a role and decide which privileges you want your client to have. This is under the tab Users.

From what I understand, there's a slight performance benefit in using perch_content() over perch_content_custom(), as the template can be cached.

Cheers,

Rachel Andrew

Rachel Andrew 394 points
Perch Support

The method you are describing is for when you are developing the site. You choose at that point which template to use, the editor role doesn't need access to change that.

If you are allowing the content editor to create new pages then you can choose a page to copy the regions from, in which case the new pages will inherit the same choices as that page. You wouldn't normally have content editors choosing the template to use.

You can also use perch_content_create to set a template and other options in code:

https://solutions.grabaperch.com/architecture/create-a-prepopulated-region

Thanks for the replies.

I'm a bit fuzzy on the proper uses of perch_content_create, perch_content_custom, and perch_content. I guess I just need to get started and see what happens.

I think I see what you're saying about choosing the template that is intended and then limiting the editor role by not allowing the template to be changed. Is that the standard practice for Perch devs?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that's the standard way to do it.

Thanks, that answers my question then.

By the way, I don't recall if that was covered in the videos section, might be a good topic for a video. Or maybe it was covered and I missed it.

Thanks again!