0

I want to extend an existing CMS system, and I'm trying to add "module" support.

My goal is to be able to apply a module by adding a marker within the database content it's self.

Example:

<p>
    My fun content that is located in a paragraph tag
</p>
[news:1234]
 <p>
    ... more fun content within a different paragraph tag
</p>

The above example is very ad hoc, but you get the picture. I'd like to be able to dynamically load a news.cshtml view and use the news feed ID of 1234.

The problem with this is that the content from the Model is the last thing over the wire, so I'm not sure how to tell the index.cshtml view to swap out the marker for the news.cshtml partial.

Any direction will be appreciated.

EDIT

I'd also be open to suggestions on how to parse the content in the controller before passing it to the view.

1
  • Its not Razor but I'm preety sure Spark View Engine allows for this by Parsing the View multiple times. Commented Jun 28, 2011 at 3:20

2 Answers 2

2

If you are not into parsing the content for your markup, another way you could do it is to place an actual div for the content to be loaded into.

<div class="news" id="1234"></div>

Then on your page have some javascript (jQuery) which filled these divs with calls to the server.

$(function() {
  $('.news').each(function() {
    $.get('/CMS/LoadNews/' + $(this).attr('id')).appendTo($(this));
  }
}
^ just off the top of my head, haven't double checked it works.

In most cases I would prefer the server side parsing, but depending on what this content is and whether it needs to be there at page load, this could be useful.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 cuz I do like the concept, unfortunately I need the site to be compatible with NON-Javascript enabled browsers.
0

Create a custom HtmlHelper extension that parses the content, calls Html.Action, updates the text with the result, and returns the content for display.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.