Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon 692 posts 1068 karma points
    Apr 18, 2015 @ 14:01
    Simon
    0

    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

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 18, 2015 @ 14:30
    Dennis Aaen
    0

    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

  • Simon 692 posts 1068 karma points
    Apr 18, 2015 @ 14:46
    Simon
    0

    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.

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 18, 2015 @ 15:03
    Dennis Aaen
    101

    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

    $(document).ready(function () {
    $('head').append('<link rel="canonical" href="http://example.com" />');
    });

    Hope this helps,

    /Dennis

     

  • Simon 692 posts 1068 karma points
    Apr 18, 2015 @ 15:13
    Simon
    0

    Hi Dennis,

    It seems a good approach.

    Sorry for asking; are there such any approaches rather than using jquery?

    Thank you.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 18, 2015 @ 15:23
    Dennis Aaen
    0

    Hi Simon,

    You could also use native Javascript for example

    /Dennis

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 18, 2015 @ 15:27
    Jan Skovgaard
    2

    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

  • Simon 692 posts 1068 karma points
    Apr 18, 2015 @ 16:05
    Simon
    0

    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.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 18, 2015 @ 19:49
    Jan Skovgaard
    0

    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

  • Simon 692 posts 1068 karma points
    Apr 19, 2015 @ 09:55
    Simon
    0

    Hi Jan,

    Makes sense :)

    Thank yoou. I will try it out.

    Kind Regards

  • Tobias Klika 101 posts 570 karma points c-trib
    Apr 19, 2015 @ 10:22
    Tobias Klika
    0

    Hi!

    What about using ViewBag or try to add data to HttpContext.Items and check for it in your layout? Doesn't this work from there?

  • Simon 692 posts 1068 karma points
    Apr 24, 2015 @ 16:34
    Simon
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft