Copied to clipboard

Flag this post as spam?

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


  • Chief 24 posts 45 karma points
    Jul 01, 2010 @ 17:22
    Chief
    0

    A simple dynamic URL in a template

    I have:

    <iframe src="http://www.facebook.com/widgets/like.php?href=http://example.com"
            scrolling="no" frameborder="0"
            style="border:none; width:450px; height:80px"></iframe>

    I want to impl. this into my master template, but can anyone tell me what to write if I want the "http://example.com" change according to which page I'm on?

    e.g www.example.com/folder/my-biography

    What I want is when people press my "Like" button it send the right url instead of 1 static like www.example.com.

  • Magnus Eriksson 122 posts 362 karma points
    Jul 01, 2010 @ 17:38
    Magnus Eriksson
    1

    I did this using XSLT like so (change iframe properties/url to fit your solution):

    <iframe class="fb_like" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:85px; height:30px;" allowTransparency="true">
    <xsl:attribute name="src">http://www.facebook.com/plugins/like.php?href=http%3A%2F%2F<xsl:value-of select="umbraco.library:RequestServerVariables('HTTP_HOST')" /><xsl:value-of select="umbraco.library:UrlEncode(umbraco.library:NiceUrl($currentPage/@id))"/>&amp;layout=button_count&amp;show_faces=true&amp;width=85&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=30</xsl:attribute>
    </iframe>

    Maybe there's a better way but this worked like a charm for me.

    Regards,
    Magnus

  • Rich Green 2246 posts 4008 karma points
    Jul 01, 2010 @ 17:56
    Rich Green
    0

    Essentially the same solution as Magnus

     <xsl:if test="$currentPage/@id != ''">
          <iframe src="http://www.facebook.com/widgets/like.php?href=http://{umbraco.library:RequestServerVariables('HTTP_HOST')}{umbraco.library:NiceUrl($currentPage/@id)}"
            scrolling="no" frameborder="0"
            style="border:none; width:450px; height:80px"></iframe
      </xsl:if>

    Create a new XSLT file, select 'clean' from the drop down (make sure you keep 'create macro' ticked)

    Paste the code above between

    <xsl:template match="/">
    <!--paste here-->
    </
    xsl:template>

    Then in your template just add the macro where ever you need the iFrame to appear.

    Rich

  • Chief 24 posts 45 karma points
    Jul 01, 2010 @ 19:24
    Chief
    0

    Thank you both - I wonder why when I insert it in e.g master template using:

    <umbraco:Macro Alias="FBlike" runat="server"></umbraco:Macro>

    It appears fine, but the rest of the page doesnt appear? ;)

     

  • Rich Green 2246 posts 4008 karma points
    Jul 01, 2010 @ 20:11
    Rich Green
    0

    Sounds like some tag is not closed correctly?

    Maybe paste the HTML that is produced here.

    Rich

  • Chief 24 posts 45 karma points
    Jul 01, 2010 @ 20:34
    Chief
    0

    Yeah .. this xslt

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:if test="$currentPage/@id != ''">
     <iframe src="http://www.facebook.com/widgets/like.php?href=http://{umbraco.library:RequestServerVariables('HTTP_HOST')}{umbraco.library:NiceUrl($currentPage/@id)}&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=recommend&amp;font=tahoma&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; width:450px; height:21px; overflow:hidden;" allowTransparency="true">
     </iframe>  
    </xsl:if>

    </xsl:template>


    Output:

    <iframe src="http://www.facebook.com/widgets/like.php?href=http://www.mysite.com/da&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=recommend&amp;font=tahoma&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; width:450px; height:21px; overflow:hidden;" allowTransparency="true" />

    It obviously removes the </iframe> and make a closing /> instead ..

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jul 01, 2010 @ 20:38
    Peter Dijksterhuis
    1

    Hi,

    change your xslt a bit. By default it outputs xml, which does not like opening and closing tags with nothing in between. So, it makes it one tag.

    To change this behaviour, change: xsl:output method="xml" into xsl:output method="html"

    HTH,

    Peter

  • Chief 24 posts 45 karma points
    Jul 01, 2010 @ 20:41
    Chief
    0

    Thats it! - solved .. than you all for being both fast and nice :-)

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jul 01, 2010 @ 21:00
    Peter Dijksterhuis
    0

    We're all just trying to spread the love for umbraco :)

    But seriously, this is called the friendliest community in CMS-land. A lot of people around to give others a hand.

    As return, you could mark one of the above answers as 'solution', so the guys that helped get a bit rewarded as well.

    Cheers,

    Peter

Please Sign in or register to post replies

Write your reply to:

Draft