I have encountered an issue where I want to add a <link rell="next"> etc.. for canonical url for pagination, in a Macro. So, I have a macro where I have the pagination logic but I want to add the <link> to the head section.
I have tried this approrach but no success, since I want to render section from a Macro. So, I want to render macro in a view, where this view is inherited from a master view.
Another approach could have to simply split the things up in to two macros.
So one macro is handling the pagination and the other is handling what needs to be in the header. You'll of course need to check if the page you're on needs to render the different link elements.
I'm not convinced that using JavaScript for dealing with canonical urls etc. is the best way to go since that even though Google claims that they read JavaScript as well I don't trust it 100% and feel that stuff like this should always be rendered server-side to avoid potential issues.
I don't see that I can achieve this using two macros, since I need to set the <link> rel="next " and rel="prev" according to the pagination logic which will be in one macro.
SO, are thare any alternatives to the javascript approach?
YES, use two macros :) - In your pagination approach I assume you're using a querystring keep track of what page you're currently on? Then using the macro that goes into the HEAD section you can make a check like Request.Querystring("page") and then store it to a variable and then based on this value you should be able to figure out what the prev/next values should be?
How can I pass data from my macro which is in a view and access the same value from masterpage? Because I want to pass the total pages from the first macro which is in the view of the Blogs. Then I want to read it from the MAcro which is in the masterpage which contains the logic for the paginated content for canonical rel="next" and rel="prev".
Access <head> section from Macro
Hi,
I have encountered an issue where I want to add a <link rell="next"> etc.. for canonical url for pagination, in a Macro. So, I have a macro where I have the pagination logic but I want to add the <link> to the head section.
I have tried with sections but no success.
Any ideas please how can I achieve this?
Thank you.
Kind Regards
Hi Simon,
Have you seen the documentation video about working with RenderSection on Umbraco TV. if not perhaps this http://umbraco.tv/videos/umbraco-v7/implementor/fundamentals/templating/advanced-master-templates/ can help you solve your case.
Hope this helps,
/Dennis
Hi Dennis,
Thank you four your fast reply.
I have tried this approrach but no success, since I want to render section from a Macro. So, I want to render macro in a view, where this view is inherited from a master view.
Hi Simon,
Okay maybe you could use a jQuery approach to solve your case to add a canonical link tag in your head section. Try to see the blogpost. http://www.rickardnilsson.net/post/Applying-stylesheets-dynamically-with-jQuery
Hope this helps,
/Dennis
Hi Dennis,
It seems a good approach.
Sorry for asking; are there such any approaches rather than using jquery?
Thank you.
Hi Simon,
You could also use native Javascript for example
/Dennis
Hi Simon
Another approach could have to simply split the things up in to two macros.
So one macro is handling the pagination and the other is handling what needs to be in the header. You'll of course need to check if the page you're on needs to render the different link elements.
I'm not convinced that using JavaScript for dealing with canonical urls etc. is the best way to go since that even though Google claims that they read JavaScript as well I don't trust it 100% and feel that stuff like this should always be rendered server-side to avoid potential issues.
Hope this input helps.
/Jan
Hi Jan,
I don't see that I can achieve this using two macros, since I need to set the <link> rel="next " and rel="prev" according to the pagination logic which will be in one macro.
SO, are thare any alternatives to the javascript approach?
Thank yoou.
Hi Simon
YES, use two macros :) - In your pagination approach I assume you're using a querystring keep track of what page you're currently on? Then using the macro that goes into the HEAD section you can make a check like Request.Querystring("page") and then store it to a variable and then based on this value you should be able to figure out what the prev/next values should be?
Hope this makes sense.
/Jan
Hi Jan,
Makes sense :)
Thank yoou. I will try it out.
Kind Regards
Hi!
What about using
ViewBag
or try to add data toHttpContext.Items
and check for it in your layout? Doesn't this work from there?Hi all or Jan,
How can I pass data from my macro which is in a view and access the same value from masterpage? Because I want to pass the total pages from the first macro which is in the view of the Blogs. Then I want to read it from the MAcro which is in the masterpage which contains the logic for the paginated content for canonical rel="next" and rel="prev".
I have tried with tempData but no success :(
thank you in advance.
Kind Regards
is working on a reply...