2

Is there a way to use razor variables in PageTemplateFeatures in C1?

I have this in MasterLayout.cshtml:

@inherits CompositeC1WebPage @{

string stylesFolder = "~/Frontend/Styles";
string jsFolder = "~/Frontend/Scripts";
string imgLayoutFolder = "~/Frontend/Images/Layout";
string imgSliderFolder = "~/Frontend/Images/Slider";
string websiteTitle = HomePageNode.Title;

}

And I'd like to reference these variables in the PageTemplateFeatures.

Thanks, Robert

1 Answers1

1

Probably not.

A Page Template Feature is actually an .html or .xml file. To make the system aware of the Razor syntax in the file, the file should be .cshtml (see also http://www.w3schools.com/aspnet/razor_syntax.asp). If you try and replace the extension of the template feature's physical file, you'll lose the feature to the system.

I have a suggestion: How about moving all the Razor related code to a Razor function and then insert this function in the template feature. The function should of course both declare variables and use them.

wysocki
  • 731
  • 5
  • 7
  • I like your suggestion, I actually considered doing that at the time I was working on this but for the sake of time stuck with the basics. I'll definitely give it a try on the next project - thank you for the answer!! – user3114686 Dec 20 '13 at 10:56
  • One thing you COULD do is to save those variables in a static class or as items in HttpContext.Current.Items. That way you can from a razor-function inserted in your PageTemplateFeature retrieve those variables again. – Pauli Østerø Jan 09 '14 at 13:07