Get the current page URL in macros rule

Raymond Rofuli asked on June 1, 2018 06:50

Hello

Just want to ask on how i can get the page URL in macros rule?

I already know the "currentdocument.nodealiaspat" but the queries data on the link are not included.

i.e. /post?data1=1&data2=2

Basically what i want to do is to have a different title and meta description for every links including the pagination pages.

and the solution i can see is using the macros rule in metadata.

in the page's title box editor: {% if(currentdocument.nodealiaspath == "/news?page=2") { %} Sample {% } %}

Thanks

Correct Answer

Peter Mogilnitski answered on June 2, 2018 20:40

Kentico Macro syntax has some limitations i.e. there is no elseif, but it is possible:

{%
// lambda expression to get parmater from query string (qp)
qp = (Param => QueryString[Param].ToLower().TrimEnd().TrimStart());

if (qp("page")==1 && qp("name")=="sample" && qp("size")=="large")
{
   return "title1"
}
else 
{
  if (qp("page")==1 && qp("name")=="sample") 
  {
    return "title2"
  }
  else 
  {
    return "default title"
  }
}
|(identity)GlobalAdministrator%}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on June 1, 2018 17:28 (last edited on December 10, 2019 02:31)

{%QueryString%}- gets query string, for example: QueryString["Page"] or QueryString.Page, {%CurrentDocument.RelativeURL|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Raymond Rofuli answered on June 2, 2018 01:58

Is this also applicable for multiple data query such as "/?page=1&name=sample&size=large" ?

I want to identify the links by their complete data query.

if(/?page=1&name=sample&size=large){ //title } elseif(/?page=1&name=sample) { //title } else { //default title }

Thanks

0 votesVote for this answer Mark as a Correct answer

Raymond Rofuli answered on June 4, 2018 04:00

Hi Peter,

Thanks for this.

This works.

I appreciated the help.

0 votesVote for this answer Mark as a Correct answer

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