Get name of a page when i have the id - Smart search

mjv fonseca asked on June 1, 2015 11:20

In my site, in the blog area it was decided to change how the blog post author. Normaly the user that creates the blog post is the author, but we wanted to be able to choose one of the members of the company.

So we added a page selector in our blogpost page were we choose the blog post creator.

To show in the blog post author in the repeater we created a custom function in the App Code

 public static string GetBlogPostAuthorName(object value)
{
    int nodeId = ValidationHelper.GetInteger(value, 0);
    if (nodeId <= 0)
        return string.Empty;


    TreeProvider tree = new TreeProvider(SiteContext.CurrentUser);

    TreeNode node = tree.SelectSingleNode(nodeId, DocumentContext.CurrentDocumentCulture.CultureCode);

    if (node != null)
    {
        return node.DocumentName;
    }
    return string.Empty;
}    

This way we get the blog post author in transformations, my problem now is how to get the name of the author in smart search.

I only get the ID but i want the name. I'm still new in Kentico and sometimes its a little hard to know how the code in Kentico works.

Thanks for the help

Recent Answers


Jan Hermann answered on June 1, 2015 15:05

Hello,

if the code is part of the CMSTransformation class as it is described here:

https://docs.kentico.com/display/K8/Adding+custom+methods+to+transformations

you can place it to the smart search transformation where you have your nodeid available.

Best regards,
Jan Hermann

0 votesVote for this answer Mark as a Correct answer

mjv fonseca answered on June 1, 2015 15:35

The way you are saying i get the value i want, but i can't get that in search, or can i?

An example, the nodeID of the page with my profile is 1 and in the smart search i can add that <%#Functions.GetBlogPostAuthorName(Eval("BlogPostAuthor")) %> and that will give me the name in the results, but i can't search for the page name, only for the ID, right?

Do i need to create a custom smart search? If so... how can i do that to retrieve what i need? I'm a little confused on that part

0 votesVote for this answer Mark as a Correct answer

mjv fonseca answered on June 3, 2015 12:18

Can anyone help me out?

I'm having some issues to retrieve the nodeName having the NodeID in a custom smart search. I'm still new in Knetico and sometimes i can't really find out to do things in Kentico

0 votesVote for this answer Mark as a Correct answer

Rui Wang answered on June 5, 2015 17:27

mjv, I think what Jan mentioned above would work if you are using a repeater to display a list.

But with the built in smart search, it doesn't return much data other than these https://docs.kentico.com/display/K8/Displaying+search+results+using+transformations

So if you truly need the name to be displayed, then you may have to use API to create the search result page.

0 votesVote for this answer Mark as a Correct answer

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