How to set smart search box results URL relatively based on url via macro?

Charles Wesley asked on February 20, 2015 01:27

Given the following page structure in Kentico v7:

  • Root
    • Alpha
      • One
        • Search
      • Two
    • Bravo
      • One
        • Search
      • Two
    • Charlie
    • Delta
    • Echo

Pages Alpha and Bravo (and their children) share the same template. On that template is a search box web part. I would like to set the search results URL to be either:

/Alpha/One/Search/ or /Bravo/One/Search depending under which node the control is rendered. It seems that the only way I can realistically accomplish this is via a macro in the search box web part's properties.

Question: How would you write a macro to dynamically set this property based on it's parent path?

Here is what I currently have but it doesn't seem to work:

/{%Split(CurrentPageInfo.DocumentURLPath, '/')[0]#%}/one/search

Correct Answer

Charles Wesley answered on February 20, 2015 18:56

Unfortunately, I wasn't able to use the repeater path convention, which was surprising.

What ultimately worked for me was similar to my initial attempt, just with correct syntax:

~/{% CurrentDocument.NodeAliasPath.Split("/")[1]|(identity)GlobalAdministrator%}/one/search

http://stackoverflow.com/a/28625255/1754037

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on February 20, 2015 06:33 (last edited on December 10, 2019 02:30)

I'd think you can do similar to how you would with a repeater's path.

/{0}/{1}/Search

Or couldn't you use something like:

{% CurrentDocument.Parent.NodeAliasPath + "/Search" |(identity)GlobalAdministrator%}
0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 21, 2015 06:37

So why hardcode the "one" node of your URL? Is the search only found under the "one" node and not under "two" or "three"?

0 votesVote for this answer Mark as a Correct answer

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