Hi Ben,
if only some of the folders on navigation level 1 should be virtual you could simply add a checkbox to the CMS that defines them as a virtual folder.
This is not tested but it should be like this:
Add a field to the database - in your /mysite/code/Page.php:
class Page extends SiteTree {
public static $db = array(
"IsVirtuaFolder" => "Boolean"
);
// etc ...
you can also set the default value (not sure if this usually defaults to false or true):
static $defaults = array(
'IsVirtualFolder' => false
);
Then add a checkbox to the CMS:
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new CheckboxField("IsVirtualFolder", "this is a virtual folder"));
return $fields;
}
update the database with /db/build?flush=1
Now you can define if any page is a virtual folder. To filter this in the template just take the same code as below and add an 'if':
<ul>
<% control Menu(1) %>
<li>
<% if isVirtualFolder %>
<span>$MenuTitle.XML</span>
<% else %>
<a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a>
<% end_if %>
<!-- add sub pages to the navigation -->
<% if Children %>
<ul>
<% control Children %>
<li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode"><span>$MenuTitle.XML</span></a></li>
<% end_control %>
</ul>
<% end_if %>
</li>
<% end_control %>
</ul>
It's untested but it should work (or at least it's close).
There is an alternative that would maybe work even better. You could just create a new page type 'VirtualFolder', all you need to do for this new page type is to remove it's Content field from the CMS (because you really only need the page title) and then in the navigation template you check if the menu item is of page type 'VirtualFolder'. If yes, just don't create a link. I guess this works with
<% if PageType = VirtualFolder %>etc...<% end_if %>
but I'm not entirely sure.
Cheers!
Anatol