Show Blog Name in Blog Post Transformation

Mike Bilz asked on November 8, 2017 01:23

Hello Kentico Team,

Is it possible to show the parent Blog Name of an individual post in a transformation?

All of the information I have found on this has been for previous versions of Kentico, and no longer seem to work.

My goal is to have a list of all of the blog posts on the site on one page, and to include the parent blog names in the transformation to help keep them distinct.

Blog name - Blog Post Title
Other Blog Name - Second Blog Post Title
etc...

Any assistance would be greatly appreciated.

Thanks.

-mike

Recent Answers


Rui Wang answered on November 8, 2017 02:58 (last edited on December 10, 2019 02:31)

Is there the month level between Blog name and Blog post, and are you using ASCX or HTML transformation?

Using Macro, it can be as simple as {% Documents[NodeAliasPath].Parent.Parent.DocumentName |(identity)GlobalAdministrator%} if you only have the Blog Name > Blog post levels.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on November 8, 2017 15:41

If you're displaying all the posts on the actual blog page then you can use something as simple as CurrentDocument.DocumentName.

What I mean is if your structure is like this:

/Blog-1/month/post
/Blog-1/month/post
/Blog-2/month/post
/Blog-3/month/post

And you have your listing viewer on the /Blog-# page, you can get that document's name if you are on that current page.

Try one of the following in your ascx transformation:

<%# CurrentDocument.DocumentName %>
<%# CurrentDocument.GetValue("BlogName") %>

0 votesVote for this answer Mark as a Correct answer

Mike Bilz answered on November 8, 2017 20:58

Hello Rui and Brenden,

This would be an ASCX transformation from a page above the blog posts, so CurrentDocument will not give the correct information. I also had no luck using Rui's macro expressions, as none of them resolved.

For reference, the Tree looks like this:

Page with Transformation
--Blog 1
----Blog Post 1
----Blog Post 4 
--Blog 2
----Blog Post 2
----Blog Post 3

And I would like the transformation to look like this:

Blog 1: Blog Post 1
Blog 2: Blog Post 2
Blog 2: Blog Post 3
Blog 1: Blog Post 4

Can this be done with a simple transformation?

Thanks.

-mike

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on November 8, 2017 21:09 (last edited on November 8, 2017 21:10)

So in that case, you'd have to perform a lookup based on the NodeParentID and get that document name. Doesn't matter if it's in C# or a Macro, both will make another call to the database for every page you render in that transformation. Your call will look something like this:

string parentName = ValidationHelper.GetString(DocumentHelper.GetDocuments().WhereEquals("NodeID", Eval<int>("ParentNodeID")).And().WhereEquals("ClassName", "cms.blog").FirstObject.DocumentName, "");

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on November 8, 2017 21:18

@Mike, what I had was macro, which you cannot use in ASCX transformation directly.

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on November 8, 2017 21:46

Mike, there is always to option to add a custom Transformation method if it's too complex to write the code in ASCX transformation directly. https://docs.kentico.com/k10/custom-development/miscellaneous-custom-development-tasks/adding-custom-methods-to-transformations

You can create a method like GetBlogName(NodeID) which you get use Document API to get the parent node name, then, when you call the method, it would be <%# GetBlogName(Eval("NodeID")) %>

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.