Skip to content

Commit ef2ff27

Browse files
committed
Add branch navigation examples to pages
Companion examples for docs PR webflow/openapi-internal#796. New pageBranching section with: - getBranchId: read branch ID of current page - getParentPageId: read source page ID - listBranches: discover all branches for a page - navigateToBranch: discover + switchPage to first branch - navigateBackToMain: getParentPageId + switchPage back
1 parent d766c18 commit ef2ff27

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

‎src/examples/pages.ts‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,79 @@ export const Pages = {
362362
await currentPage.setOpenGraphDescription(description)
363363
},
364364
},
365+
366+
// Page Branching
367+
pageBranching: {
368+
getBranchId: async () => {
369+
const currentPage = (await webflow.getCurrentPage()) as Page
370+
371+
const branchId = await currentPage.getBranchId()
372+
if (branchId) {
373+
console.log('Currently on branch:', branchId)
374+
} else {
375+
console.log('This page is not a branch.')
376+
}
377+
},
378+
379+
getParentPageId: async () => {
380+
const currentPage = (await webflow.getCurrentPage()) as Page
381+
382+
const parentPageId = await currentPage.getParentPageId()
383+
if (parentPageId) {
384+
console.log('Branch source page ID:', parentPageId)
385+
} else {
386+
console.log('This page is not a branch.')
387+
}
388+
},
389+
390+
listBranches: async () => {
391+
const currentPage = (await webflow.getCurrentPage()) as Page
392+
393+
const branches = await currentPage.listBranches()
394+
if (branches.length > 0) {
395+
console.log(`Found ${branches.length} branch(es):`)
396+
for (const branch of branches) {
397+
console.log(` pageId: ${branch.pageId}, branchId: ${branch.branchId}`)
398+
}
399+
} else {
400+
console.log('No branches found for this page.')
401+
}
402+
},
403+
404+
navigateToBranch: async () => {
405+
const currentPage = (await webflow.getCurrentPage()) as Page
406+
407+
// Discover branches
408+
const branches = await currentPage.listBranches()
409+
if (branches.length === 0) {
410+
console.log('No branches found.')
411+
return
412+
}
413+
414+
// Navigate to the first branch
415+
const allPages = await webflow.getAllPagesAndFolders()
416+
const branchPage = allPages.find((p) => p.id === branches[0].pageId)
417+
if (branchPage) {
418+
await webflow.switchPage(branchPage)
419+
console.log('Switched to branch:', branches[0].branchId)
420+
}
421+
},
422+
423+
navigateBackToMain: async () => {
424+
const currentPage = (await webflow.getCurrentPage()) as Page
425+
426+
const parentPageId = await currentPage.getParentPageId()
427+
if (!parentPageId) {
428+
console.log('Not on a branch page.')
429+
return
430+
}
431+
432+
const allPages = await webflow.getAllPagesAndFolders()
433+
const parentPage = allPages.find((p) => p.id === parentPageId)
434+
if (parentPage) {
435+
await webflow.switchPage(parentPage)
436+
console.log('Switched back to main page.')
437+
}
438+
},
439+
},
365440
}

0 commit comments

Comments
 (0)