K13 @Html.Kentico().PageTitle with macro that depends on query param

Rory Aherne asked on May 23, 2025 11:41

Hi,

I have a custom macro in Metadata.Title that returns a value depending on an id query param. It works for the first call of the page but any successive calls to that page with different id query params return the result from the first call to the page.

I'm not caching the results of my macro anywhere. Using the same macro to set the og:title meta tag works as expected when the ids are changed.

Is there any way around this?

Correct Answer

Rory Aherne answered on May 26, 2025 12:06

Removed the method from my master page and created my own using this:

//return pageDataContext.Metadata.Title; //cached, don't use
var result = MacroResolver.Resolve(pageDataContext.Page.DocumentPageTitle);
if (string.IsNullOrWhiteSpace(result))
    return pageDataContext.Metadata.Title;
return result;
1 votesVote for this answer Unmark Correct answer

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