2

I have two lists of different PageTypes - NewsItems and PressReleases. They are displayed in one list each, with links to the individual items.

Now I want to include the press release items into the news list and use the style of the news items to display them as news items. They share properties like "Heading" and "BodyText", which are used in the News Template.

I imagine that it won't be that difficult to feed the NewsItems' ListPage with both sets of pages, but I don't understand how I can control the rendering of the item page.

I would like to take the PageData object from a NewsItem OR a PressReleaseItem and display it using the News-Item.aspx template, if it is selected in a NewsList. But EPiServer will always render the PressReleaseItem with the PR-Item.aspx since it's coupled in the PageType settings.

Anyone know how to accomplish this?

EDIT: An effort to clarify:

The important issue is how to know the "list parent" and choose the right template from that. In the ListPage I can apply different looks on the PR and News items respectively using tompipes answer, but when selecting to see an individual item EPi will render the PR-Item-1 the same way regardless of their "list parent". That's the problem.

Conceptual design

Niklas Wulff
  • 3,497
  • 2
  • 22
  • 43

3 Answers3

2

I'm not following exactly what you are attempting here. But I think I get the gist of it.

Why not use one aspx template for both page types, but in the code behind switch off sections using the visible attribute.

If you are using PageTypeBuilder you could use the "is" keyword:

somePlaceHolder.Visible = CurrentPage is NewsItemList;

If you're not using PTB, you could use something like:

somePlaceholder.Visble = CurrentPage.PageTypeID == 10;

or

somePlaceholder.Visble = CurrentPage.PageTypeName == "NewsItemList";

I'll point out now I'm not a fan of hardcoding anything, so I would place the template name, or ID into a config file, or a property on the start/root page to avoid hardcoding them.

Let me know if this will help, or if I have misunderstood please try elaborate on your issue.

tompipe
  • 949
  • 6
  • 8
  • This sounds simple and smart, will look into my code and see if it solves it, thanks! – Niklas Wulff Nov 23 '11 at 12:49
  • Actually it's not solving the problem. When the item page is loading, I want to know which page that opened it and choose the layout from that. Your solution works great in the list view though. – Niklas Wulff Nov 23 '11 at 13:58
1

Depending on how much the templates share you could go with user controls, placeholders or even different masterpages to switch view in a suitable way.

To know when to switch you could use a querystring parameter, session variable or the nicest looking way would probably be to lookup and get the list's PageData object by the HTTP referrer. If it's empty you will get press release rendering as the worst case.

Johan Kronberg
  • 1,086
  • 7
  • 12
0

I tried lots of solutions, including the adding of querystring to the PR items in the list links, the getting of referring url in the item template and different types of event hooking for automatic publishing of news items from a PR item (although I only looked at the code samples for that one), and finally came to the conclusion that they all had something that told me not to go that way. (Making the code too complex, or the markup logic too hard to understand and so forth)

I ended up using Fetch data from another EPiServer page, and creating a "shortcut pagetype" in which I let my editors pick which PR item should be used as base for a news item.

This shortcut pagetype is called "PR-as-news-itemPage" and it is rendered with the same aspx as ordinary news items: News-Item.aspx. Having no properties of its own, it will take all relevant data from the PR item selected with "Fetch..."

To render PR items with all its properties I created an ordinary new pagetype called PR-Item.aspx. This renders the "Attribute 2" property, which is only rendered by PR-item.aspx, and not by News-Item.aspx.

(I could have gone even simpler, by letting the editors use the old News-Item page type and use the "Fetch..." property there, but I have some mandatory properties in that page type which I didn't want to make optional for this sake.)

Niklas Wulff
  • 3,497
  • 2
  • 22
  • 43