Hi, Drew. In theory your code is ok, but I suspect that the extension is going to be called too late (on the render stage, not before), so, changing the page's Title property will have no effect. If you want your page's title to depend on certain conditions then more correct approach should be for example to develop a separate macro that renders a title string and place it to the template like this:
Currently I render the title just how you demonstrated - its the standard way. Then inside that Macro you choose the value using the logic you add. This works fine.
On my current site, I have a template which is used to display pages dynamically from a third party API that provides event information. This is simply a call to a 'GetDynamicEventData' macro, which takes in an event ID and pulls the data from the API, creating a dynamic page for that event. This also works well.
But I want to set the page Title to the title of the Event. This can't be done, since they're in two seperate macro's.
So my options are:
1) Move my dynamic event template from under the general 'site layout' template - which defines the Head, script reference, title, header, footer, etc. But this means duplicate of the 'general layout' code in two templates.
2) Make a call in my Title macro, so if its a dynamic event page - pull in the API data here and use it to set to the title. This will mean there will be two API calls. One by the Title macro and the next by the macro called in the template body - which displays the event content itself. Really, this means two API calls every time we render a page (but yes, I can look at increasing cachine times, etc).
3) See if I can dynamically set the Title tag from within the 'dynamic event' macro.
Option 2 is the simplest, but I wanted to see if I could avoid two API calls where one could suffice.
Although I do use FeedCache2 - I don't want to cache the event data on a per-event basis - it needs to be dynamic. (I do cache the data already, for display lists of events and search capability, but ideally 'event pages' need to display realtime data)
I would rather develop a small extension method that calls the 3d party application and caches the result in HttpContext.Items (or HttpContext.Cache if longer caching is possible) and then returns the result of the call. Then I would make both macros call this extension - the first will render the title and the second will render the content. The advantage will be that both macros remain independent from each other and from the page where they're placed on and there'll still be only one call to the exetrnal system.
This was option 4 - caching the data somewhere else.
It's a good suggestion - but I've decided to opt for the "just look at the cached XML events data to get individual data", rather can calling the API. This means I can access the data from the Title tag macro and 'show event details' page macro without any extra API calls (infact, no API calls at all)
If I've got more time, I'll create a custom app that caches the data itself :)
XsltExtension > Modify Page (?)
Is it possible to modify the page that a macro is called on, from an XsltExtension?
Specifically, the Title tag attribute?
For example, this doesn't work when called in a macro - the Title on the page is not affected:
There's a good reason for me wanting to do this :)
(of course, I can explain why if anyone wants to know - but it will be a long post) :)
Cheers,
Hi, Drew. In theory your code is ok, but I suspect that the extension is going to be called too late (on the render stage, not before), so, changing the page's Title property will have no effect. If you want your page's title to depend on certain conditions then more correct approach should be for example to develop a separate macro that renders a title string and place it to the template like this:
Ok, let me explain the situation.
Currently I render the title just how you demonstrated - its the standard way. Then inside that Macro you choose the value using the logic you add.
This works fine.
On my current site, I have a template which is used to display pages dynamically from a third party API that provides event information.
This is simply a call to a 'GetDynamicEventData' macro, which takes in an event ID and pulls the data from the API, creating a dynamic page for that event.
This also works well.
But I want to set the page Title to the title of the Event.
This can't be done, since they're in two seperate macro's.
So my options are:
1) Move my dynamic event template from under the general 'site layout' template - which defines the Head, script reference, title, header, footer, etc. But this means duplicate of the 'general layout' code in two templates.
2) Make a call in my Title macro, so if its a dynamic event page - pull in the API data here and use it to set to the title. This will mean there will be two API calls. One by the Title macro and the next by the macro called in the template body - which displays the event content itself.
Really, this means two API calls every time we render a page (but yes, I can look at increasing cachine times, etc).
3) See if I can dynamically set the Title tag from within the 'dynamic event' macro.
Option 2 is the simplest, but I wanted to see if I could avoid two API calls where one could suffice.
Although I do use FeedCache2 - I don't want to cache the event data on a per-event basis - it needs to be dynamic.
(I do cache the data already, for display lists of events and search capability, but ideally 'event pages' need to display realtime data)
Cheers,
I would rather develop a small extension method that calls the 3d party application and caches the result in HttpContext.Items (or HttpContext.Cache if longer caching is possible) and then returns the result of the call. Then I would make both macros call this extension - the first will render the title and the second will render the content. The advantage will be that both macros remain independent from each other and from the page where they're placed on and there'll still be only one call to the exetrnal system.
This was option 4 - caching the data somewhere else.
It's a good suggestion - but I've decided to opt for the "just look at the cached XML events data to get individual data", rather can calling the API.
This means I can access the data from the Title tag macro and 'show event details' page macro without any extra API calls (infact, no API calls at all)
If I've got more time, I'll create a custom app that caches the data itself :)
is working on a reply...