Different CSS and JavaScript Files Per Page

Topics: Writing themes
Nov 20, 2013 at 10:56 AM
I have a bunch of different pages in my website which contain HTML code in the body part of each page. This HTML code makes use of some JS libraries (and CSS files as well), which get referenced at the top and the bottom of the page respectively.
My problem is that I don't need all CSS and JS files in all of my pages; the homepage needs file1.js and file1.css, the contact page needs file2.js and file2.css etc. Therefore I cannot use the Documents.html's override to reference all my files.
Is there any way to reference only the required files in each page?

Thanks for the help,
Nov 20, 2013 at 12:14 PM
Here two methods (Script/Style.Require with resource manifest and Script/Style.Include) are explained.

http://stackoverflow.com/questions/10243345/how-to-include-style-sheets-and-js-files-inthe-view-of-orchard-cms

In order to place the script tags in head or foot, you can use Script.Include("filename.js").AtHead() or Script.Include("filename.js").AtFoot() as well.


Nov 20, 2013 at 2:27 PM
If using float Different CSS Positioning to control how elements are laid out doesn't provide the measure of control ypu're looking for you can use the CSS positioning attributes. To position elements yourself you first have to choose a positioning scheme with the position property There are four positioning schemes three of which you will actually use. The four are static relative absolute and fixed. The static scheme is the default Elements flow down the page from left to right and top to bottom unless you use the float property=used to indicate that an element should be placed as far as possible to the left or right on the page and that any other content should wrap around it. This is one of the best illustrated example First take a look at the absense of math in my historywill I have fear for not pasing yhe subject detract somewhat from the interest but if it be judged useful by those inquirers who desirs an exact knowledge of the past as an aid to the interoretation of the future which in the course of human things must resemble If it does not reflect it I shall be content. In fine I have wriiten my work not as an essay which is to win the applause of the moment but as a possession for all time.

The absense of math in my history will I have fear for not pasing yhe subject detract somewhat from the interest but if it be judged useful by those inquirers who desirs an exact knowledge of the past as an aid to the interpretation of the future which in the course of human things must resemble If it does not reflect it I shall be content.


The absense of math in my history will I have fear for not pasing yhe subject detract somewhat from the interest but if it be judged useful by those inquirers who desirs an exact knowledge of the past as an aid to the interpretation of the future which in the course of human things must resemble If it does not reflect it I shall be content. In fine I hav written my work not as an essay which is to win the applause of the moment butas a possession for all time.

The absense of math in my history will I have fear for not pasing yhe subject detract somewhat from the interest but if it be judged useful by those inquirers who desirs an exact knowledge of the past as an aid to the interpretation of the future which in the course of human things must resemble If it does not reflect it I shall be content. In fine I hav written my work not as an essay which is to win the applause of the moment butas a possession for all time.

As you can see the three boxes run straight doen the page I've added a border to the first box but that's it. Here's the source code to the page with the addition of a few additional properties that demonstrate how float works;

Input

,DOCTYPE html>
<html>
<head> <title>Floated Elememts</title> <style type "text/css" media"screen> .right { border: 3px solid black; padding: 10px; margin: 10px; float: right; width: 33% .bottom { clear: both; } </style> </head> <body>
<p class="right">
<p>
<p class="main"> </p> <p class="bottom"> </p> </body>
</html>
<
Nov 20, 2013 at 2:57 PM
I'd like to thank you for your quick answer, but I think I didn't explain my problem clearly...
Referencing the required CSS/JS files using the methods mentioned above is fair enough. My question is if I can use different files per page.
For example, my home page makes use of a JS file, but my contact page doesn't, so I don't have to reference it in both places (perhaps using the Document.cshtml file).
So, is there a way to control which CSS/JS files get referenced for each page?

Thanks in advance,
Nov 20, 2013 at 4:01 PM
Maybe there is a module for including scripts and css files per page (URL), but I am not aware of any. Normally, these resources are not specified for pages, but for views. The pages are composed of content, widgets and layout (Layout.cshtml and Document.cshtml, shared for all). Content and widgets are composed of parts, which have views for them as razor files. According to your needs (different urls, content types etc.), you will need to create alternate views (http://docs.orchardproject.net/Documentation/Alternates) in your theme, and in the view you will need to include the style and scripts.

Good luck.


Marked as answer by ggouts on 11/21/2013 at 12:30 AM
Nov 21, 2013 at 7:30 AM
Thanks a lot for your help!
Nov 21, 2013 at 7:41 PM
I am using alternates based on url to have dedicated groups of layout!.cshtml, this way I segment the necessay css or js.
MayPageGroup1Layout-url-theUrlOfThisGroup.cshtml
Marked as answer by ggouts on 11/22/2013 at 12:27 AM
Nov 22, 2013 at 7:27 AM
Yes CSADNT, I think this is the most appropriate method to get things done!

Thanks all of you for your help!