0

I'm trying to customize blog site, I've found examples hot to customize templates with CSR, but that doesn't work with blog.

Here is the example of code I used:

    function registerBlogsRenderer()
{
    var blogContext = {};
    blogContext.Templates = {};
    blogContext.Templates.Fields = {
        "Body": {
            "View": func1
        },
        "Title": {
            "View": func1      
        },
        "Author": {
            "View": func1      
        }       
    };
    blogContext.Templates.Footer = func1;


    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(blogContext);
}

Everything works fine with the fields, but nothing happens to Footer and Header.

I use Summary view for my blog with Boxed view style

Please give me any hint how can I catch different parts of blog post element, such as header, footer or any others. What are their names to apply to them. Post few strings of example code if possible, please.

I know I can use OnPostRender but I hoped I could customize post elements partially, not the whole HTML block at once.

  • I beg my pardons, i trimmed all the code to make my question more simplier for readers. This is what my func1 does: code function func1(ctx) { return "<b>FUNC1</b>" } code – Alexander Larin Jun 15 '16 at 17:25
0

Your func1 probably throws an error when it tries to access a property of ctx like ctx.currentItem. That's an assumption based on the fact you use func1 for fields as well as for the footer. In that case you should be able to see a text similar to "TypeError: ctx.CurrentItem is null" in the footer of your list.

Maybe we can help you better when you show us what func1 is actually doing.

UPDATE:

I modified your code and tested it successfully on a blog site. Please try this code:

(function(){
    var blogContext = {};
    blogContext.Templates = {};
    blogContext.Templates.Fields = {
        "Body": {
            "View": func1
        },
        "Title": {
            "View": func1      
        },
        "Author": {
            "View": func1      
        }       
    };
    blogContext.Templates.Footer = func1;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(blogContext);
})()

function func1(ctx) { 
    return "<b>FUNC1</b>" 
}

BTW: Setting the view style to boxed will have no effect when you use custom CSR.

Update 2:

Summary View is a server-rendered view and CSR will not be applied to it

  • I would not go so far as to say Header and Footer usually only take a string. They are just as capable of being assigned a function as any other property of Templates. – Dylan Cristy Jun 15 '16 at 17:03
  • I removed that statement. – Daniel Stölzner Jun 15 '16 at 17:13
  • @DanielStölzner, thank you for the answer. I added comment to show what func1 does. I see console in both Chrome and IE, there were no errors related to possible exceptions, throwned by my code. I just see that frontpage of blog shows post with some stuff at the bottom and i would like to have access to all parts of the template it uses. The code i have allows me only operate with fileds templates related to post items. In most views these parts are called like Header and Footer but blog seems to be smth outstanding))) – Alexander Larin Jun 15 '16 at 17:32
  • @AlexanderLarin Please see my updated answer for working code. – Daniel Stölzner Jun 15 '16 at 18:01
  • @DylanCristy thanks for ur help too, sorry, i confused ur nicknames first) – Alexander Larin Jun 15 '16 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.