Forum

Thread tagged as: Question

How to manage navigation for single page website?

I'm building a single page vertical scrolling website using Perch. Instead of adding new pages on the back-end for each section, users add a new region, which includes fields for section ID and section title. I'd like to be able to add a new navigation item to the main nav when a user adds a new page section, and pass these fields to it, but I'm not sure how to go about this.

Any advice?

Jason Bradberry

Jason Bradberry 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

One option might be to split it into logical 'pages' even though it's all one page. You can set e.g.

PerchSystem::set_page('/contact.php');

part way though a page, and Perch will start treating it as a new page.

Otherwise, I think you'd need to manage your navigation as a region.

Thanks Drew.

I can't see a way to use set_page() in this case as the 'pages' are multiple item regions, so the page would need to be set in the template.html file, which won't accept php.

When you say manage navigation as a region, do you mean add a seperate multi-item region for navigation and just re-add the section titles and IDs there?

Is there a better way to approach this? I've been thinking through the possibility of adding each section as an actual page in Perch instead of a region, but I think I'd still need to use set_page(), and from what I understand, it looks like you'd need to hard code your page paths in to use this method.

I'm keen to find a good solution here (even if I need to rethink my whole approach) as I build a lot of this type of site, and Perch is a perfect fit, if I can work this out!

Drew McLellan

Drew McLellan 2638 points
Perch Support

There's lots of ways you can approach it. How do you manage adding a new section that would appear in the nav?

I've set up a multiple item region for the sections. Here's the code I've used in my template file.

<section id='<perch:content id="section_id" type="text" label="Section ID" required="true" urlify="true" />' class='page' allowempty="false" required="true" escape="true" />;'>
<h1><perch:content id="section_title" type="text" label="Section title" required="true" html="true" title="true" /></h1>
...
</section>

Looking at this now, I can't see any way of reusing the ID and title fields in the navigation, unless I use a region to manage my navigation and pulll the fields in using dataselects.

I'm getting the feeling I shouldn't be using regions to manage my sections.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You could generate the navigation by displaying the region using a different template that only outputs the section headings and links.

Perfect, had forgotten about the ability to reuse content using perch_content_custom!

Working a treat, thanks for the help.