Developer forum

Forum » Development » Best practices for implementing breadcrumbs in DW9?

Best practices for implementing breadcrumbs in DW9?

Thomas Berthelsen
Reply

Hi.

Currently looking into implementing breadcrumbs. Any code examples that does things similar? 

Thomas


Replies

 
Nicolai Pedersen
Reply

Hi Thomas

Take a look at this page: https://doc.dynamicweb.com/template-tags/introduction/concept/navigation#sideNavTitle1-1

How they should look and behave in terms of best practices you have to Google, i.e. https://www.nngroup.com/articles/breadcrumbs/ or https://www.searchenginejournal.com/breadcrumbs-seo/255007/

BR Nicolai

 
Thomas Berthelsen
Reply

On another note, assuming i want a pageID from a page matching the URL? Can you do that in DW? 

 

Thomas

 
Thomas Berthelsen
Reply

On another note, assuming i want a pageID from a page matching the URL? Can you do that in DW? 

 

Thomas

 
Nicolai Pedersen
Reply

A url does not only resolve to an ID - it solves ot another URL with a number of parameters. It could be a product or something else so that you would have a url that resolves to a querystring - i.e. /myproducts/bikes/mongoose-bike/blue will resolve to ?ID=123&GroupID=G12&ProductID=P23&VariantID=V34 or something similar.

But if you are in code somewhere in the frontend context, i.e. in a layout template, you can always use @PageView.Current.ID to get the ID of the current page.

Almost any code you have, happens after the URL rewrite, so you can also just do Request.QueryString("ID") or similar.

But tell me your scenario, and I can tell you the solution.

BR Nicolai

 
Thomas Berthelsen
Reply

I see, well i want the ID based on an entry url given FromUri. eg: /api/page/url?url=myurl.

So i want whatever information i can get about that page from its url using the ID that matches the url, if that makes sense?

Thomas

 
Nicolai Pedersen
Reply

It makes no sense... :-).

I do not know in what code you are trying to do this.

But try Dynamicweb.Frontend.Pageview.Current.Page

 
Thomas Berthelsen
Reply

Ok. An example could be if i have a page /api/page/url?url=Forside. I'd like to send the data along with the requested page, metadata, Content, Seo etc. As your API relies a lot on the Id (which makes perfect sense) in order to search efficiently in the database, can i somehow pull out an ID from from the Uri "Forside". A way to do it would be to set Menutext == urlname, but that would quickly break :(.

 
Nicolai Pedersen
Reply

Hi Thomas

A URL in Dynamicweb is resolved as the first thing of the page life cycle in a routehandler that hands over the request to the DynamicwebHttpHandler. The handler will create an instance of a PageViewModel object, see https://doc.dynamicweb.com/api-docs#article=8175ac67-de8b-696a-7436-6505c1a61e47, and you do no longer have a URL. You have an object with all the information you need - including the ID of the page. You do not need to resolve the URL at all...

If you want to send information for the given URL, you do that by altering the template (usually a Razor file - the view). Meta data etc. is handled in the backend and send out in the template.

You still have not told where you write your code? Is it in a Dynamicweb template? Is it a notification subscriber? Something else? Or did you create a VS project and do something in there? 

Please clarify.

BR Nicolai

 

 
Thomas Berthelsen
Reply

Hi

Thank  you for taking your time, this is my first time hands on with DynamicWeb. 

Code is written is C# .Net. I'm trying to implement a Getpage(string url). Dynamicweb already support Dynamicweb.servies.pages.Getpage(id), and i'd like to use that.

Somehow i'd need to translate my url to an Id, or is there something i misunderstand here?

Thomas.

 
Nicolai Pedersen
Reply

Yes, you misunderstand something.

I can only repeat my previous posts. You cannot and shall not call a method like Getpage(string url) - it makes no sense. It is difficult to help you if you do not answer the questions I ask...

Where do you write you code and why?

 

You must be logged in to post in the forum