Developer forum

Forum » CMS - Standard features » Device Layouts with Razor

Device Layouts with Razor

Adrian Ursu
Reply

Hi Guys,

I am trying to use separate device layouts for mobile, tablet and desktop while using razor version of the templates for all of them.

While I have tested on a separate solution the way it worked for HTML templates, for Razor templates it does not seem to work. Meaning that no matter what I do. it does not detect the device.

I have switched between HTML and razor, it seems that the global tag Global:DeviceIsMobile is rendered only in the HTML version of the template.
Could this be a bug in the Razor implementation?

Have anyone experience something similar?

Thanks in advance.


Adrian


Replies

 
Adrian Ursu
Reply

Really?

Nobody?

 
Mikkel Ricky
Reply

In Razor templates you should rarely use global tags, but instead use the API objects available, e.g.

@if (Pageview.Device == Dynamicweb.Frontend.PageView.DeviceType.Mobile) {
    <div>Mobile</div>
} else if (Pageview.Device == Dynamicweb.Frontend.PageView.DeviceType.Tablet) {
    <div>Tablet</div>
} else {
    <div>Desktop</div>
}

If really you want to get a global tag in Razor, you have to use @GetGlobalValue, e.g.

@GetGlobalValue("Global:Device.IsDesktop")
@GetGlobalValue("Global:Device.IsTablet")
@GetGlobalValue("Global:Device.IsMobile")

and these work fine (for me at least).

See the section Global tags in Razor templates [http://developer.dynamicweb-cms.com/Admin/Public/DWSDownload.aspx?File=Files%2fFiler%2fDocumentation%2fDesign%2f(en-US)+Razor+templates.pdf] for details.

I have no problems using device layouts with Razor templates, and the device layouts are handles long before Razor actually processes the templates.

If it does not work for you, then please report back what version of Dynamicweb you are running and also the user agent strings of the devices you use for testing (use http://user-agents.me/whats-my-user-agent or similar tools to get the user agent string).

Best regards,
Mikkel

 

 
Adrian Ursu
Reply

Hi Mikkel and thanks for the info.

I want to use Device layouts and I am using version 8.4.0.3. In previous versions it was working fine.

We have managed to get the info using razor tags but i was looking to use the Device Layouts functionality and avoid a bunch of Ifs.
I have seen a bug fix on version 8.4.1 regarding Device layouts being broken. Any ideea if that's what I am experiencing?

Thanks,

Adrian

 
Mikkel Ricky
Reply

Yeah, that bug is most likely what you're experiencing*. The fix fixes some caching issues with device layouts and that's probably why it seems to work for me running 8.4.0, but doesn't work out in the real world (where cache is not cleared so often as on my developer machine).

Thank you.

*  I should really start reading those bug fix notes …

 
Bo Lindblom
Reply

I can see it they still not working in ver 8.6.1.4.
Do you know when it being fixed?

Best regards

/Bosse

 

You must be logged in to post in the forum