Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional inclusion of scripts/css #34

Closed
tommck opened this issue Aug 16, 2011 · 5 comments
Closed

Conditional inclusion of scripts/css #34

tommck opened this issue Aug 16, 2011 · 5 comments

Comments

@tommck
Copy link

tommck commented Aug 16, 2011

I have shared views which are used in 2 different situations (Desktop/iPad). I have a test in my Site.Master to include the CSS for the iPad (lots of overriden styles) if the requesting user is using an iPad. Unfortunately, Cassette puts all of this stuff together, it seems.

How can I accomplish this, given that they're the same exact views?

@andrewdavey
Copy link
Owner

You will need to split your styles into separate modules (folders) for the two scenarios. Something like this in your project:

/styles/desktop
/styles/ipad

Are detecting the user agent (e.g. iPad Safari) server side? Or do you want to use a media query (based on screen width)?
For the former, something like this in the view could work:

@{
if (Request.IsIPad()) { // for example
    Assets.Styles.Reference("styles/ipad");
} else {
    Assets.Styles.Reference("styles/desktop");
}
}

For the media query (which I think is a better approach in general), please wait for the new version of Cassette which adds support for defining the stylesheet link media attribute. I'm hoping to get this released next week.

@tommck
Copy link
Author

tommck commented Aug 18, 2011

RIght, but this would require I put an if/then/else in every file instead of just in the Site.Master, right?

@tommck
Copy link
Author

tommck commented Aug 18, 2011

Media queries are nice if you're only detecting size and orientation, but the UI is different when we're on the iPad. Different stylings, different font sizes, etc. We don't want the font sizes to change based on the size of the person's browser window

@andrewdavey
Copy link
Owner

If the styles are site-wide then put the if-else Reference calls in your master page.

Otherwise, you may want to look into adding a extension method to StylesheetAssetManager that does the if-else and calls Reference with the required path. (Assuming you have some predictable for desktop and iPad stylesheet names.)

@Assets.Stylesheets.ReferenceForRequestingDevice("styles/example")

@andrewdavey
Copy link
Owner

I'm closing this issue as I don't think Cassette itself needs to handle this. It's possible to extend and customize Cassette in your application code.
Let me know if you need any more help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants