One option would be sending the UID data to the homepage using routes.
This (untested) option would let you use your subpages to populate your one-pager, as well as have actual subpages (maybe you want mysite.com/about
to link to an actual page, not an anchor on the main page).
The pages that will be used to populate the homepage should not have an associated template.
Additional subpages (like the example above) should have their own templates.
config.php:
<?php
c::set('routes', array(
array(
'pattern' => '(:any)',
'action' => function($uid) {
// see if a page with this UID actually exists
$page = page($uid);
// if yes, AND if that page has an associated template, go to it.
if ($page && (string)$page->template() == (string)$page->intendedtemplate()) {
return site()->visit($page);
// if not, go to the homepage, and send the UID along as a variable named 'scroll'
} else {
$data = array(
'scroll' => $uid,
);
return array('/home', $data);
}
}
)
));
place the variable $scroll
in your template somewhere that you can grab it with javascript:
<body data-scroll="<?= isset($scroll) ? $scroll : null; ?>">
This PHP is shorthand for:
if (isset($scroll) {
echo $scroll;
} else {
echo null;
}
Then, for example, using jQuery, find the name of the div you want to scroll to, its position, and then scroll to it:
$(window).load(function() {
var targetDiv = $('body').attr('data-scroll');
var position = $("#" + targetDiv).offset().top;
$('body').scrollTop(position);
})