Pregunta

I've created an alternate view for the detail page of a contentitem.

In this view I try to add the facebook commentsplugin to this view. The necessary javascript includes for the plugin to work are added.

This works

<div class="fb-comments" data-href="http://*************/@(Model.Header.Parent.ContentItem.AutoroutePart.Path)" data-numposts="1" data-colorscheme="light"></div>

This not

<div class="fb-comments" data-href="@(Model.Header.Parent.ContentItem.AutoroutePart.Path)" data-numposts="1" data-colorscheme="light"></div>

Is there a way to get the full url in an Orchard Alternate View like Request.Url.ToString()?

¿Fue útil?

Solución

This can be read with ViewContext

<div class="fb-comments" data-href="@(ViewContext.HttpContext.Request.Url.ToString())" data-numposts="1" data-colorscheme="light"></div>

Otros consejos

I got the comments plugin and the like button now working with the following workarround in jQuery

<div class="fb-comments" data-href="@(Model.Header.Parent.ContentItem.AutoroutePart.Path)" data-numposts="1" data-colorscheme="light"></div>


<div id="fb-root"></div>
<script>
  $(function () {
    if ($('.fb-comments, .fb-like').length > 0) {
        $('.fb-comments, .fb-like').each(function () {
            var href = location.protocol + "//" + location.hostname + "/" + $(this).data("href");
            $(this).attr("data-href", href);
        }).promise().done(includeFacebook);
    } else {
        includeFacebook();
    }

});

function includeFacebook() {
    (function (d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/nl_NL/all.js#xfbml=1&appId=##########";
        fjs.parentNode.insertBefore(js, fjs);
    } (document, 'script', 'facebook-jssdk'));
}

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top