I am adding some support to print specific pages of my site in a nice printer-friendly format. So the first thing I did was create a more-or-less blank Layout that I can drop content into. Then I went to a content page and assigned this layout to the "Print" device in Presentation Details.
That does not seem to do anything. I'm still getting the exact same output on Print Preview that I saw before I defined any Print settings. To开发者_JS百科 be honest, I'm not entirely sure how this should work. Presumably, my browser has to request the page again with a new user agent (???) to get Sitecore to return a different rendering of the page... but I've tried Firefox, Chrome, and IE and get the same undesired output from my "Default" device.
Must be missing something obvious?
The Print device, by default, will be used when there is a ?p=1
querystring value on the page you want to print. The print preview in the browser is simply previewing the page with the Default device.
Try putting that querystring in the address and see if you get the layout you are expecting.
As you noted, there is the ability to switch Device via a Browser Agent, but that won't be useful here. That would mainly be used for mobile device detection.
To access print device dynamically on anchor click, do following
default.aspx
<asp:HyperLink ID="hlPrintLink" runat="server">
</asp:hyperlink>
//default.aspx.cs
HospitalDirectionsPageItem objHospital = Sitecore.Context.Item;
string deviceName = "print";
DeviceItem deviceItem = Sitecore.Context.Database.Resources.Devices.GetAll().Where(d => d.Name.ToLower() == deviceName.ToLower()).First();
if (deviceItem != null)
{
hlPrintLink.NavigateUrl = Sitecore.Links.LinkManager.GetItemUrl(objHospital) + "?" + deviceItem.QueryString;
}
精彩评论