How to cherrypick Page Templates to show the user

Posted by Community Admin on 04-Aug-2018 15:53

How to cherrypick Page Templates to show the user

All Replies

Posted by Community Admin on 20-Mar-2017 00:00

So you have the doc to limit the "Types" of templates to show the user by overriding the TemplateSelectorDialog.

But from there how can I add rules for the templates themselves outside of rebuilding this whole control?... I've tried finding the control and tweaking it's datasource, but looks like from the source it's not possible?

 

protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
    this.TaxonomiesRepeater.DataBinding += TaxonomiesRepeater_DataBinding;
    this.TaxonomiesRepeater.ItemDataBound += TaxonomiesRepeater_ItemDataBound;
 
    base.InitializeControls(container);
 
private void TaxonomiesRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    //Repeater for each Type, ex, Bootstrap, Foundation
    var item = ((System.Web.UI.WebControls.RepeaterItem)e.Item);
    var dataItem = item.DataItem as HierarchicalTaxon;
 
    var templateRepeater = item.FindControl("templatesRepeater") as Repeater;
    var datasource = templateRepeater.DataSource as List<PageTemplate>;
 
    templateRepeater.DataSource = datasource.Where(x => x.Name == "Medportal.Medportal.MVC.Core");
 

Posted by Community Admin on 20-Mar-2017 00:00

Ah nm, got it... can hook into PreRender

this.TaxonomiesRepeater.PreRender += TaxonomiesRepeater_PreRender;

Posted by Community Admin on 20-Mar-2017 00:00

You know what, nm... issue back on the table.  While they stop showing up, there's now a script error that prevents items from being clickable.

 

**EDIT**

The only way this works is on the client, have to find the wrapper <li> and display:none it.  This sample is a little overblown as I wired up a config element to allow me to dynamically secure the list.

private void TaxonomiesRepeater_PreRender(object sender, EventArgs e)
    var templates = Util.MpConfig.PageTemplates;
    var repeater = sender as Repeater;
    foreach (RepeaterItem typeRepeater in repeater.Items)
    
        var templatesRepeater = typeRepeater.FindControl("templatesRepeater") as Repeater;
 
        // The items are not "Databound"
        foreach (RepeaterItem template in templatesRepeater.Items)
        
            var wrapper = template.FindControl("templItem") as HtmlControl;
            var title = ((SitefinityLabel)template.FindControl("templateName")).Text;
 
            var match = templates[title];
            if (match == null)
            
                //No match, no show
                //template.Visible = false;
                wrapper.Attributes.Add("style", "display: none");
            
            else
            
                //Found the match, check permissions
                if (match.IsAdminTemplate)
                
                    var currentProfile = Util.GetCurrentProfile();
                    //Hide if the user is not an admin
                    if (!currentProfile.IsSysAdmin)
                    
                        //template.Visible = true;
                        wrapper.Attributes.Add("style", "display: none");
                    
                    else
                    
                        //Okay we are a sys admin, but are you one of the allowed sysadmins?
                        if (!match.AdminsAllowedToView.ToLower().Contains(currentProfile.UserName.ToLower()))
                            //You are NOT in this list
                            //template.Visible = false;
                            wrapper.Attributes.Add("style", "display: none");
                        
                    
                
                else
                
                    //Do nothing, just show it
                
            
        
    

This thread is closed