CodeGarden 10: The sixth annual Umbraco Developer Conference
June 23-25th 2010 - free ASP.NET MVC pre-conference. Register today!

extending blog 4 umbraco

Go directly to solutionA reply has been marked as a solution
2/5/2010 2:51:20 AMAvatarcurlybubLocation: Philippinesposts: 87Karma: 61

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

2/5/2010 2:15:23 PMAvatardandrayneLocation: Edinburghposts: 893Karma: 1649
Comment with ID: 25503

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

2/6/2010 4:27:08 PMAvatarcurlybubLocation: Philippinesposts: 87Karma: 61
Comment with ID: 25567

Hi,

Thank you for your reply. I'm using the old blog for umbraco. I'll try your suggestion. Again. Thank you so much.

 

Regards,
Harry

2/8/2010 8:16:57 AMAvatarcurlybubLocation: Philippinesposts: 87Karma: 61
Comment with ID: 25617

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

2/8/2010 11:45:41 AMAvatardandrayneLocation: Edinburghposts: 893Karma: 1649
Comment with ID: 25639

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.

Dan

2/8/2010 2:29:18 PMAvatarcurlybubLocation: Philippinesposts: 87Karma: 61
Comment with ID: 25662

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?

Thank you.

Regards,
Harry

2/8/2010 3:30:45 PMAvatardandrayneLocation: Edinburghposts: 893Karma: 1649
Solution Comment with ID: 25679
0

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>

Dan

2/9/2010 2:33:35 AMAvatarcurlybubLocation: Philippinesposts: 87Karma: 61
Comment with ID: 25729

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:

&lt;%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %&gt;&lt;asp:Content ContentPlaceHolderID="head" runat="server"&gt;&lt;style type="text/css" media="screen"&gt;</p>
<p>&nbsp;#page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }</p>
<p>&lt;/style&gt;&lt;/asp:Content&gt;</p>
<p>&lt;asp:Content ContentPlaceHolderID="body" runat="server"&gt;&lt;div id="content" class="widecolumn"&gt;&nbsp;&lt;div class="post"&gt;&lt;h2&gt;&lt;umbraco:Item field="pageName" runat="server"&gt;&lt;/umbraco:Item&gt;&lt;/h2&gt;&lt;umbraco:Item field="createDate" formatAsDate="true" runat="server"&gt;&lt;/umbraco:Item&gt; by &lt;umbraco:Item field="writerName" runat="server"&gt;&lt;/umbraco:Item&gt;&lt;br/&gt;</p>
<p>&lt;div class="entrytext"&gt;&lt;umbraco:Item field="bodyText" runat="server"&gt;&lt;/umbraco:Item&gt;&lt;/div&gt;</p>
<p>&lt;/div&gt;</p>
<p>&lt;umbraco:Macro Alias="BlogPostListComments" runat="server"&gt;&lt;/umbraco:Macro&gt;</p>
<p>&lt;h3 id="respond"&gt;Leave comment:&lt;/h3&gt;&lt;umbraco:Macro Alias="frmBlogComment" runat="server"&gt;&lt;/umbraco:Macro&gt;</p>
<p>&lt;/div&gt;&lt;/asp:Content&gt;

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. 

2/9/2010 2:34:42 AMAvatarcurlybubLocation: Philippinesposts: 87Karma: 61
Comment with ID: 25730

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:

&lt;%@ Master Language="C#" MasterPageFile="/masterpages/BlogMaster.master" AutoEventWireup="true" %&gt;&lt;asp:Content ContentPlaceHolderID="head" runat="server"&gt;&lt;style type="text/css" media="screen"&gt;</p>
<p>&nbsp;#page{ background: url("/images/kubrickbgwide.jpg") repeat-y top; border: none; }</p>
<p>&lt;/style&gt;&lt;/asp:Content&gt;</p>
<p>&lt;asp:Content ContentPlaceHolderID="body" runat="server"&gt;&lt;div id="content" class="widecolumn"&gt;&nbsp;&lt;div class="post"&gt;&lt;h2&gt;&lt;umbraco:Item field="pageName" runat="server"&gt;&lt;/umbraco:Item&gt;&lt;/h2&gt;&lt;umbraco:Item field="createDate" formatAsDate="true" runat="server"&gt;&lt;/umbraco:Item&gt; by &lt;umbraco:Item field="writerName" runat="server"&gt;&lt;/umbraco:Item&gt;&lt;br/&gt;</p>
<p>&lt;div class="entrytext"&gt;&lt;umbraco:Item field="bodyText" runat="server"&gt;&lt;/umbraco:Item&gt;&lt;/div&gt;</p>
<p>&lt;/div&gt;</p>
<p>&lt;umbraco:Macro Alias="BlogPostListComments" runat="server"&gt;&lt;/umbraco:Macro&gt;</p>
<p>&lt;h3 id="respond"&gt;Leave comment:&lt;/h3&gt;&lt;umbraco:Macro Alias="frmBlogComment" runat="server"&gt;&lt;/umbraco:Macro&gt;</p>
<p>&lt;/div&gt;&lt;/asp:Content&gt;

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. 

2/9/2010 2:35:16 AMAvatarcurlybubLocation: Philippinesposts: 87Karma: 61
Comment with ID: 25731

Sorry for the double post, I cant get the code window to output the same as yours. Hehe.

2/9/2010 2:42:45 AMAvatarcurlybubLocation: Philippinesposts: 87Karma: 61
Comment with ID: 25733
 <%@ 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

Pages:

Please login or Sign up To post replies