Expand my Community achievements bar.

SOLVED

Append the PageName or Querystring to the script variable

Avatar

Level 4

Hi All,

We have a requirement to append the PageTitle in the javascript when the page field input from the component is 'search' or append the query string from the URL when the page input is 'I/O'.So ,could anyone please let me know how to achieve this logic .

 

Thanks in Advance!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You can render the pageTitle and adshow from backedn based on conditions like env, component type etc. 

But from client side, check if there is a query param then change the javascript object pageOptions values from client side javascript.

You can write this logic in the same script tag.



Arun Patidar

View solution in original post

3 Replies

Avatar

Community Advisor

Hi,

COuld you please explain with example? do you want to do it in Author or this is for end user.

The page title you can get it from document

console.log(document.title)

 



Arun Patidar

Avatar

Level 4

Hi @arunpatidar ,

 

We have two different pages i.e.,Search and I/O page, in the site. So , we are developing a new component which renders google ad script in the enduser page to integrate the ads from third party tools . So, one of the script variable is pageType that should render the PageName when the input is selected as search in the component or renders the query parameter from the URL when the input is selected as I/O.Also the second variable 'adshow' should be seen only in the non-prod environment.So please let me know your thoughts on how to achieve this requirement.

 

JS used in HTML:

var pageOptions =

{
"pageType": "${search term/query}",

"adshow": "on",
"linkTarget":  '_blank' 
}
;

 

Thanks in Advance!

Avatar

Correct answer by
Community Advisor

You can render the pageTitle and adshow from backedn based on conditions like env, component type etc. 

But from client side, check if there is a query param then change the javascript object pageOptions values from client side javascript.

You can write this logic in the same script tag.



Arun Patidar