User control in blog markup

Posted by Community Admin on 04-Aug-2018 00:20

User control in blog markup

All Replies

Posted by Community Admin on 14-Apr-2013 00:00

I've submitted a support request for this, but it has not been resolved. I figured I would give the community a stab at it.

I want to add a user control to the blog widget. Instead of listing the author name, I have a custom field with a list of names. These names correspond with a specific page. I display this name and have some logic which creates a link to the author page.  This link is supposed to display on the publicly facing frontend. This link is generated by a usercontrol I am referencing in the widget markup on the backend. 

I am editing the widget by going to /Sitefinity/Design/ControlTemplates and clicking on the Blog widget template. I added a reference to my control:
<%@ Register Src="~/Controls/BlogAuthor.ascx" TagPrefix="uc1" TagName="BlogAuthor" %>

And, in the widget, I added :
<uc1:BlogAuthor runat="server" ID="BlogAuthor" AuthorName='<%# Eval("SelectedAuthor")%>' />

The code of BlogAuthor.ascx (my control) is only being execute when I am logged into sitefinity. When I go to the blog page after logging off, the server code is not executed.

Maybe I am missing something in the provided link, but I am not sure how to get the code behind to execute when I am not logged in.

Here is the control referenced in the widget:

<%@ Control Language="C#" AutoEventWireup="true"  %>
<%@ Import Namespace="Telerik.Sitefinity" %>
<%@ Import Namespace="Telerik.Sitefinity.Modules.Pages" %>
<asp:HyperLink runat="server" ID="authorLink"></asp:HyperLink>
<asp:Literal runat="server" ID="authorText"></asp:Literal>
 
<script runat="server">
     public string AuthorName get; set;
 
    protected void Page_Load(object sender, EventArgs e)
    
        var bioPage = App.WorkWith().Pages().Where(x => x.Title.ToString().ToLower() == AuthorName.ToLower()).Get().FirstOrDefault();
 
        if (bioPage != null)
        
            authorLink.Visible = true;
            authorLink.NavigateUrl = bioPage.GetFullUrl();
            authorLink.Text = AuthorName;
        
        else
        
            authorText.Visible = true;
            authorText.Text = AuthorName + "<!-- bio for author not created -->";
        
    
 
</script>

Thanks,
Kevin

Posted by Community Admin on 16-Apr-2013 00:00

Kevin,

Hmm, it may be bombing out because of the "App.WorkWith().Pages()" part. Once you log out, the code isn't running as a logged in user anymore and starts trying to access ALL pages (even back-end ones).

Change that to:

App.WorkWith().Pages().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)

Posted by Community Admin on 17-Apr-2013 00:00

Hello Kevin,

This will work if you map your custom template containing the user control declaration. Create an ascx file and place the markup for your blog list template. Then drop the Blogs list widget on a page and go to Edit->Advanced and find the layoutTemplatePath field. In it provide the relative path to your template. Locate the TemplateKey field, remove the Id string in it and save the changes. 

Kind regards,
Pavel Benov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed