Dynamically Set Page Title in Transformation - Basic Uni View

Vic Carter asked on March 17, 2014 15:47

I have a query UniView that is using the following code in its transformation:

    <script runat="server"> 
protected override void OnDataBinding(EventArgs e) 
    CMSContext.CurrentTitle = Eval("NewsHeadline").ToString();

This obviously sets the page title to the value of my news headline.  However in another section using a Basic Universal Viewer, when I try to implement similar code, nothing happens.  Is there a specific method I should be calling in a Basic Uni View that is triggered when the data is loaded?  Any help would be appreciated.

Recent Answers

Brenden Kehren answered on March 18, 2014 06:23 (last edited on December 10, 2019 02:30)

A transformation is not the place to set the page title because you are enumerating though a list of records and will get unexpected results. You can use a macro in the Properties>Metadata>Page title. For instance if your document name is the same as your news headline {%DocumentName%} Or if you wanted to check the doc type and use a different field {%if(ClassName == "cms.news"){NewsHeadlline}else{DocumentName}|(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Richard Sustek answered on March 18, 2014 07:33

Hi Vic,

Thank you for your message.

I have dealth with an attempt to change page title in transformation so I can confirm that this is not possible. The page state in which the transformations are resolving is after the last chance you have for changing page title.

You can change the page title programatically outside the transformation, although its better to use our settings for that in page properties. You can also use macros there so you might create a custom macro to get your page title.

Kind regards,

Richard Sustek

1 votesVote for this answer Mark as a Correct answer

Vic Carter answered on March 18, 2014 10:47

In the instance above, I am only ever dealing with on record(it is a detail page) and oddly enough this works just fine for my news section, the above code does actually set the title based on the headline. I was wondering if there was a macro(thanks Brenden) that may accomplish the same thing. I will give this a try and see what happens. Any idea why it works for my Query Uni View and not with a Basic Uni View?

Thanks for your answers. :)

0 votesVote for this answer Mark as a Correct answer

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