In Agility, you have control over what C# code gets executed when a module is rendered on your website. Typically, in an ASP.NET MVC solution, you'll have the option of an MVC Controller Action, a Partial View or Inline Code.
MVC Controller Actions and Partial Views must be integrated directly into your website code base. While Inline Code can be managed directly in the Content Manager and published/synchronized with your website code base. Inline Code is ultimately executed by your website code base, but the source code is not integrated into your website source code.
While Inline Code is a quick and easy way to get code live, it can become an issue managing your distributed code across Inline Code and your website code base.
This guide will walk you through how to move code that has been set up in Inline Code and integrate that into your website code base.
What You'll Need
You'll need to have access to your website source code, as well as access to the Inline Code files within the Agility Content Manager. For this, you'll need at least the Designer user role.
Migrating Module Inline Code to your Website Code Base
An Inline Code file for a Module is the exact same as a Partial View in your website code base, but it just doesn't exist in your website code base and instead is stored in the cloud. In these steps, you'll create Partial Views for each of your Module Inline Code files, copy the contents, and update your Module Definitions to use the new Partial View.
- In Agility, navigate to Settings > Inline Code > Module Definitions
- Open an item and copy the contents of the file to your clipboard
- Then, in Visual Studio create a new Partial View (.cshtml) in your website code under the Views directory. Name your file something that corresponds to the name of your Module Definition. Take note of the relative path of the file (i.e. ~/Views/Modules/SampleInlineCodeModule.cshtml)
- Now that you have your code integrated into your website code base, you'll want to change the Output Template that the Module Definition is using to Partial View and set the path to your view in your website code. You can do this by navigating to Settings > Module Definitions and select your corresponding Module Definition. Then, click on the Output Template tab.
Ensure you change the value from Inline Code to Partial View on Website and set your path. - Click Save & Close. Do NOT publish the module definition. It's important that you leave this change in a Staging state so that your live website doesn't start trying to find a partial view that does not exist yet.
- Now, you can test this locally. If you've copied the contents of the code correctly, it should work without any changes.
- Once you've verified your code is working correctly in a local environment, you can then proceed to deploy the website code base to your uat website environment. You can then Preview then the website in that environment and again, verify this is working correctly.
- When ready, you can then deploy your website code base to production. At this point, you still haven't published your Module Definition so viewing your uat or live website is still using inline code files, while in a preview mode you are actually using the Partial View files in your website.
- The last step is to Publish your module definition(s) to publish the change of Output Template typed for the Module Definition.
Comments
Please sign in to leave a comment.