Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow showing or hiding breadcrumb trail on a page #509

Open
CrispinF opened this issue Jun 25, 2020 · 4 comments
Open

Allow showing or hiding breadcrumb trail on a page #509

CrispinF opened this issue Jun 25, 2020 · 4 comments

Comments

@CrispinF
Copy link
Contributor

See https://www.cloudscribe.com/forum/thread/how-can-i-have-breadcrumbs-on-some-page-and-not-others

Needs a bit of thought about how best to implement this. We wouldn't want to show a page setting that appears to switch on a breadcrumb trail if it's not present in the theme layout. Can SimpleContent be aware as to whether the theme does or does not include the breadcrumb component?
This is included by default in our bootstrap 4 sample themes as follows:
@await Component.InvokeAsync("Navigation", new { viewName = "Bootstrap4Breadcrumbs", filterName = NamedNavigationFilters.Breadcrumbs, startingNodeKey = "" })

But we could have a page setting that hides the breadcrumb - that would not be as confusing, as an editor would not use it if no breadcrumbs are displaying on the site. Ideally the setting would only appear if breadcrumbs are included in the layout - see previous question!

@StewartBellamy
Copy link
Contributor

I have MVC razor views that I also don't want the breadcrumbs to show on. Currently I'm setting the body css class and using css to hide it. This is mainly on the full width/height map pages.

I don't see a way that the SimpleContent page editor can know if breadcrumbs are in the layout or not.

Perhaps the behaviour of of the current menu filters needs changing, i.e. rather then still showing the breadcrumb and just not including the current page it could hide the breadcrumb instead? But maybe this current behaviour is still desirable too.

@JimKerslake
Copy link
Collaborator

JimKerslake commented Sep 29, 2021

No, there is no way that the simplecontent system can 'know' whether its contents are being rendered into an outer Theme _layout that does or does not support breadcrumbs... and the breadcrumb rendering component is of course from a different CS library altogether.

It is presumably simple enough to add a boolean HideBreadcrumbs property to the simplecontent page viewmodel, and make that UI-editable.

The architectural problem then comes when rendering the contents of that into the outer Theme _Layout, which will have no explicit access to that property - because the overall _Layout does not formally 'know' the type of the ViewModel... for all it knows SimpleContent might not be installed at all... the job of the _Layout is to wrap around a bunch of underlying (partial) views and it is these that know formally about their required ViewModel types. And again the breadcrumb component is from a different CS library altogether, which knows nothing of SimpleContent.

Tactics to get around that latter point therefore are either:
1 - @StewartBellamy 's approach above of using JS in the simplecontent page partial view to muck about with the DOM of the outer page elements outside of itself (like BODY), change their CSS classes and thereby hide the breadcrumbs. I would wonder if you might sometimes see the elements rendered momentarily before they get hidden though.
or
2 - Actually it is possible to use some reflection in the outer _Layout to infer the (dynamic) ViewModel type and search for a hypothetical boolean 'HideBreadcrumbs' property... then surround the breadcrumb rendering call with an 'if'.
I would normally shy away from doing that kind of reflection on every page... but it probably could work.

Perhaps, better than that, the reflection work could be pushed down to the breadcrumbs rendering component, something like
@await Component.InvokeAsync("ConditionalNavigation", new { viewName = "Bootstrap4Breadcrumbs", filterName = NamedNavigationFilters.Breadcrumbs, startingNodeKey = "", model=Model })
And if you didn't want it, you would use the old default one in your _Layout instead.

@JimKerslake
Copy link
Collaborator

oops - closed by accident :/

@JimKerslake
Copy link
Collaborator

JimKerslake commented Sep 29, 2021

Verified that a conditional navRenderer like that could work... although I think it violates the conceptual separation of the various cs components - cs.Navigation would be rendering conditionally based upon a property that is declared in SimpleContent, even though these components are supposedly independent/autonomous - which doesn't feel right. Maybe keep the 'glue' back out in the _Layout.

This would also require a migration to add new 'HideBreadcrumbs' field to cs_Page, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants