This project is read-only.

Inject Dynamic Content into Page Html

Topics: Customizing Orchard
Sep 25, 2013 at 3:04 AM
Edited Sep 25, 2013 at 3:05 AM
I need to inject parameter values obtained from a database into the href of various anchor tags in the HTML of a Page content type.

For example:
<p><a href="MyUrl?MyParameter1=MyParameterValue1" target="_blank"> </a></p>
A new tab should open for each link and display only the contents of the page at the specified URL (i.e., no content from the Orchard site). I need to know when the page is rendered so that I can execute some code to obtain each parameter value from a database and then replace the its token (e.g., MyParameterValue1) with the actual value.

What is the best way to do something like this in Orchard?

I tried creating a custom module with a razor view that renders the above anchor tag as the return shape of the Display method of the module's ContentPartDriver, but it just displays its URL in the content area of a new page in the context of the Orchard site and waits for a user to click on the link.
Sep 25, 2013 at 3:47 AM
I'm not sure if this is the best way in Orchard, in fact it's plain MVC, and I'm aware this is rather replacing than injecting, but, you can implement a controller in your module, put the URLs in your page that point to an action of that module, replace the url and parameters in the action and do

return Redirect(theNewUrl);

at the end to send the user to the page you want.

Sep 25, 2013 at 11:07 PM
Your suggestion worked, kassobasi. Thanks!