问题
Let's say we have two pages in Orchard CMS. The homepage and the About US page. I want to use a RoyalSlider on the homepage which has its own CSS file. How do I include it only on the homepage and not on the about us page?
In Orchard CMS I am using Contoso as the theme and I tried including the royalslider.css file on the Layout.cshtml
using Style.Include
but this will include the CSS file over all the pages in the website which is not a good practice.
回答1:
You should use URL Alternates feature for that. It's described here, in the section "URL and Widget Alternates".
After enabling the feature, copy the Layout.cshtml
you found in your theme and rename it to Layout-url-homepage.cshtml
. This one will only be used for rendering the homepage, so just add your Style.Include
calls there and you're set.
回答2:
You can try 2 things.
Use the Classy feature in Vandaley Industries module (http://gallery.orchardproject.net/List/Modules/Orchard.Module.Vandelay.Industries). Then you can add a script to any content type.
Create an alternate at the corresponding URL.
They are many other ways, as Orchard is SOOOO extensible. Try these two first. :)
来源:https://stackoverflow.com/questions/12854474/adding-different-css-files-to-different-pages-in-orchard-cms