Defining globals

Topics: Customizing Orchard, General, Writing modules, Writing themes
Apr 27, 2011 at 4:55 AM


Im having a problem rendering Images and Scripts. Everything was ok until i installed a blog and tried going to Archives section (for any date). The page doesnt load and try searching resources at <url>/blog/archive/<year>/ and then my route. If i use the full path it works fine, but doesnt seem correct as it is prone to change in future when uploading to server. So my question is, which is the best way to handle this and ios there any way to define globals/constants, like my full address, and access it somehow from anywhere in the CMS?


Apr 27, 2011 at 7:58 AM

For resources (scripts, etc.) you can create an IResourceManifest and define a string Id and the file location. Look at the existing jQuery module for how it defines all the different jQuery includes.

For global constants like an address, I'd take a different approach. You could actually do that as small template pieces, i.e. shapes. So create a template file in ~/Views; for example call it FullAddress.cshtml. Then you can include that anywhere else using @Display.FullAddress(). It can be overridden or updated any time, in other themes or modules, and you can even hook into shape events like IShapeTableProvider to manipulate it thru code.

Apr 29, 2011 at 4:59 AM

Not sure to understand the first part. The Manifest should be placed where? In my theme folder? And then how would i call the resource from the different views? Im quite confused about the workflow i guess. Also, i try searching for definitions of classes and i cant find anything. Arent there any Code docs?

As regarding the second issue, i tried using @Display.FullAddress() and the view is correctly loaded. However, when trying to access the variable defined in this view from another view the debugger says its out of scope. Any ideas?