Is it possible to do something like this in Razor:
@using(Html.CMSContent("TermsOfService"))
{
<text>
<!-- Some default content goes here if the "TermsOfService"
item doesn't exist in my content table in the database -->
</text>
}
When the view is being processed, if the CMSContent helper doesn’t find a content item named “TermsOfService” in some database table I’ve set up, it’ll output the default content.
Otherwise, it’ll replace the default content with what’s in the database?
I’m trying to build a CMS/application hybrid, so that the Marketing department can override the text in my app if they want.
CLARIFY
The reason I’m doing this is to make the code super-easy to read and write. I’m going to end up with these little content blocks all over the place, so I’m hoping to minimize how much a developer has to type to get this functionality.
I’m also expecting that 99% of the time, the default text is what’s going to show up. But I’d like to have the 1% cases handled where we need to quickly change some text without having to re-deploy the app. So, having the default text as close to its context as possible is important (ie, I don’t want the developer to have to jump to a different file to see what the default text is – nor have to jump to the top of the page).
For example, when you do @using(Html.BeginForm()) it’ll automatically emit the start and end <form> tags. I’m hoping for something clever like that.
I think I figured out what I was looking for. It uses an
ifinstead ofusing:For the helper:
Although I’m not sure that using Response.Write is the best way to do it.