Hi,
We installed the blog 4 umbraco package, it is working as it should. But we need to put some security measures when it comes to posting comments on the blog entry. What we want to do is that when a user wants to comment on the blog post they should be logged in first and the name and email fields should be populated already with their name and email address (information is already available on the members area) after logging in.
Can we do this without the source code? Do you have any idea where I can get the soure code of the blog 4 umbraco package?
Do you have any idea on how to do this?
Thank you.
Regards,Harry
Hi Harry
I haven't yet used the new blog4umbraco, but if the comment form is an xslt macro you can wrap the following function around it
<xsl:if test="umbraco.library:IsLoggedOn()"> <!-- Comment form --> <xsl:variable name="currentMember" select="umbraco.library:GetCurrentMember()" /> </xsl:if>
Also shown is getting the current member in xslt , and at our.umbraco.org/.../getmember you'll see how to access member properties.
Dan
Thank you for your reply. I'm using the old blog for umbraco. I'll try your suggestion. Again. Thank you so much.
Hi the old blog4umbraco package is using a user control for the comment form. Is there a way that I can check if the user is logged in before they can give a comment to the blog post?
Thank you.Regards,Harry
For the c# code you'd need to find someone else, sorry!
What you can do (and what I have done) is to create different templates for users who are and aren't logged in. One template would contain the usercontrol that allows commenting and one wouldn't. Like the following
<xsl:variable name="loggedInTemplate" select="2387" /><xsl:variable name="loggedOutTemplate" select="2388" /><xsl:variable name="currentId" select="$currentPage/@id" /> <xsl:choose> <xsl:when test="umbraco.library:IsLoggedOn()"> <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedInTemplate)" disable-output-escaping="yes" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedOutTemplate)" disable-output-escaping="yes" /> </xsl:otherwise> </xsl:choose></xsl:template>
RenderTemplate takes a template ID and the ID of the current page as parameters and can easily be used to do what you are after.
Wow! This xslt amazes me. However I cannot understand what this xslt does. Do you have a working sample that I can view online? I'm more on the designing part, I guess I need to have someone help me with this one.
Again, I'll give it a try. Can you explain further?
No problem,
Ok in the above example I've got two "blog post" templates. One of the templates includes a comment form and one has a message saying "You much be logged in to post comments". Both of these templates are allowed on the blog post page, but the default (3rd) template contains only the above macro, which takes the IDs of the two optional templates (logged in/logged out) and renders the correct one based on whether or not the user is logged in.
<!-- template ID for logged in users --><xsl:variable name="loggedInTemplate" select="2387" /><!-- template for logged out template --><xsl:variable name="loggedOutTemplate" select="2388" /><!-- current page ID --><xsl:variable name="currentId" select="$currentPage/@id" /><!-- is user logged in? --> <xsl:choose> <xsl:when test="umbraco.library:IsLoggedOn()"> <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedInTemplate)" disable-output-escaping="yes" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="umbraco.library:RenderTemplate($currentId,$loggedOutTemplate)" disable-output-escaping="yes" /> </xsl:otherwise> </xsl:choose></xsl:template>
Thanks again.Lets say I have created a template already and got their ID numbers on the properties tab. Where do I place this xslt that you've created? I checked the templates for the old blog4umbraco and under the blogPost template is the Leave a Comment link.
Here is the code for the blogPost template:<%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %><asp:Content ContentPlaceHolderID="head" runat="server"><style type="text/css" media="screen"></p> <p> #page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }</p> <p></style></asp:Content></p> <p><asp:Content ContentPlaceHolderID="body" runat="server"><div id="content" class="widecolumn"> <div class="post"><h2><umbraco:Item field="pageName" runat="server"></umbraco:Item></h2><umbraco:Item field="createDate" formatAsDate="true" runat="server"></umbraco:Item> by <umbraco:Item field="writerName" runat="server"></umbraco:Item><br/></p> <p><div class="entrytext"><umbraco:Item field="bodyText" runat="server"></umbraco:Item></div></p> <p></div></p> <p><umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro></p> <p><h3 id="respond">Leave comment:</h3><umbraco:Macro Alias="frmBlogComment" runat="server"></umbraco:Macro></p> <p></div></asp:Content>
<%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %><asp:Content ContentPlaceHolderID="head" runat="server"><style type="text/css" media="screen"></p> <p> #page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }</p> <p></style></asp:Content></p> <p><asp:Content ContentPlaceHolderID="body" runat="server"><div id="content" class="widecolumn"> <div class="post"><h2><umbraco:Item field="pageName" runat="server"></umbraco:Item></h2><umbraco:Item field="createDate" formatAsDate="true" runat="server"></umbraco:Item> by <umbraco:Item field="writerName" runat="server"></umbraco:Item><br/></p> <p><div class="entrytext"><umbraco:Item field="bodyText" runat="server"></umbraco:Item></div></p> <p></div></p> <p><umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro></p> <p><h3 id="respond">Leave comment:</h3><umbraco:Macro Alias="frmBlogComment" runat="server"></umbraco:Macro></p> <p></div></asp:Content>
I assume that the xslt that you gave me should be triggered after clicking the Leave a comment link.
Whoa! Im going in circles. Hehe.
Sorry for the double post, I cant get the code window to output the same as yours. Hehe.
<%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %><asp:Content ContentPlaceHolderID="head" runat="server"><style type="text/css" media="screen">#page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }</style></asp:Content><asp:Content ContentPlaceHolderID="body" runat="server"><div id="content" class="widecolumn"> <div class="post"><h2><umbraco:Item field="pageName" runat="server"></umbraco:Item></h2><umbraco:Item field="createDate" formatAsDate="true" runat="server"></umbraco:Item> by <umbraco:Item field="writerName" runat="server"></umbraco:Item><br/><div class="entrytext"><umbraco:Item field="bodyText" runat="server"></umbraco:Item></div></div><umbraco:Macro Alias="BlogPostListComments" runat="server"></umbraco:Macro><h3 id="respond">Leave comment:</h3><umbraco:Macro Alias="frmBlogComment" runat="server"></umbraco:Macro></div></asp:Content>
There I think I got to past the code correctly. :D