Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Printing Blog Name in Blog Post Title View modes: 
User avatar
Member
Member
scott_hancock-urmc.rochester - 1/29/2014 2:43:52 PM
   
Printing Blog Name in Blog Post Title
I'd like to use a macro to print the name of the parent blog as part of the blog post's title.

Here is what I'd like to do:

1. Go to the Blog Month document of the blog post.
2. Go to Properties > Metadata.
3. Under Page Title Uncheck "inherit".
4. In page title put the following macro:
{%documentname%} - {% CMS.Blogs.BlogHelper.GetParentBlog(Eval<int>("DocumentID"), false).DocumentName %}

This will set the page title of all the blog posts in that month to be Document Name - Blog Name.

Unfortunately, this doesn't work. I get an error that says: "[MacroExpression.Evaluate]: 'GetParentBlog' is not a known method name." Is there any way to do this?

Thanks,
Scott

User avatar
Member
Member
kentico_sandroj - 1/29/2014 7:27:16 PM
   
RE:Printing Blog Name in Blog Post Title
Hi Scott,

I was able to reproduce this issue so I searched for workarounds and this is what I found so far:
{%CurrentDocument.Parent.Parent.DocumentName%}

Since the structure is typically:
Blog
-BlogMonth
--BlogPost

The aforementioned macro will be able to get the Blog document name. If your structure is different, you would include more less .Parent as needed. Would this work for you?

Please let me know if you have any questions.

Best Regards,
Sandro

User avatar
Member
Member
scott_hancock-urmc.rochester - 2/5/2014 1:23:51 PM
   
RE:Printing Blog Name in Blog Post Title
Hi,

That won't work. Since I put the value in the Blog month, so it will be inherited by all the posts below it, the blog month's title will be messed up. Do we not have access to the GetParentBlog in the API from macros?

In the meantime i've created a custom macro do to it.


public static string GetParentBlogName()
{
if (CMSContext.CurrentDocument.ClassName.ToLower() == "cms.blogpost" || CMSContext.CurrentDocument.ClassName.ToLower() == "cms.blogmonth")
{
return CMS.Blogs.BlogHelper.GetParentBlog(CMSContext.CurrentDocument.DocumentID, false).DocumentName;
}
else
{
return string.Empty;
}
}

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 2/5/2014 1:30:35 PM
   
RE:Printing Blog Name in Blog Post Title
Another option would be to place your macro text inside of a static text webpart, this will be the macro that you want to render the title, then set the visible condition of the webpart to a macro ie if currentdoc type = "cms.blogpost"

User avatar
Member
Member
scott_hancock-urmc.rochester - 2/5/2014 2:39:38 PM
   
RE:Printing Blog Name in Blog Post Title
I just tried {%Document.GetParentBlogName%} which I found using a macro editor and that doesn't work either.

User avatar
Member
Member
kentico_sandroj - 2/6/2014 3:48:19 PM
   
RE:Printing Blog Name in Blog Post Title
Hello,

Document.GetParentBlogName is not an available option by default in the v7 macro editor but in any case it seems that the custom macro is the best approach due to the way you would like to use the macro. It should also be possible to write a conditional statement that uses a different version of the macro based on which page you are on but the custom macro would be a better approach.

Please let me know if you have additional questions.

Best Regards,
Sandro

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 2/6/2014 4:51:05 PM
   
RE:Printing Blog Name in Blog Post Title
Going off of what Sandro mentioned for a typical blog setup:

Blog
-Blog Month
-- Blog Post

I have a macro that looks at the ClassName property and sets the values accordingly.
{%if(ClassName == "cms.blog" || ClassName == "cms.blogmonth"){ SiteObjects.Blogs.DisplayNames[0] + " - "}else{""}%}