How to output HTML to another point on the page from within a Macro v6
For a site I'm working on I have a base template and then a child template for a 2 column page. The right-hand column can contain panels that display quotes from happy clients. 1 quote per panel. A page may have a maximum of 1 client quote and 1 candidate quote. When these quotes are clicked on a pop up box containing the full quote pops up in the centre of the screen using javascript. The popupboxes blur out the entire page in the background. In order to get this to cover the entire page the HTML for the pop-up box must sit outside of the main page structure, below it for example.
In order to keep the site fresh the client wants these quotes being chosen at random from a pool of 9 candidate quotes and 9 client quotes.
I currently have a razor macro that is called once from within right hand column to render the panels and once outside of the main page structure to render the matching popup boxes. I need to find some way of passing or sharing an id for the selected quotes between the macros. I've been trying to store and retrieve values in the viewbag from within the macro but so far no luck. Syntactically it seems happy but when I inspect the viewbag its always empty.
Maybe I'm doing something wrong, no idea! here's a short example...
if (quoteType == "Candidate Quote") { if (Model.ViewBag.CandidateQuoteID == "") { // GET AVAILABLE QUOTE CONTENT var QuoteContainer = Model.Children.Where("DocumentTypeAlias == \"contentFolder\" && name == \"Candidate Quotes\""); AvailableQuotes = QuoteContainer.First().Children.Where("DocumentTypeAlias == \"Quote\""); // select quote int SelectedQuote = new Random().Next(AvailableQuotes.Items.Count); //store for accompanying panel Model.ViewBag.Add("CandidateQuoteID", SelectedQuote.ToString());
How to output HTML to another point on the page from within a Macro v6
For a site I'm working on I have a base template and then a child template for a 2 column page. The right-hand column can contain panels that display quotes from happy clients. 1 quote per panel. A page may have a maximum of 1 client quote and 1 candidate quote. When these quotes are clicked on a pop up box containing the full quote pops up in the centre of the screen using javascript. The popupboxes blur out the entire page in the background. In order to get this to cover the entire page the HTML for the pop-up box must sit outside of the main page structure, below it for example.
In order to keep the site fresh the client wants these quotes being chosen at random from a pool of 9 candidate quotes and 9 client quotes.
I currently have a razor macro that is called once from within right hand column to render the panels and once outside of the main page structure to render the matching popup boxes. I need to find some way of passing or sharing an id for the selected quotes between the macros. I've been trying to store and retrieve values in the viewbag from within the macro but so far no luck. Syntactically it seems happy but when I inspect the viewbag its always empty.
Maybe I'm doing something wrong, no idea! here's a short example...
Hi Sam,
why don't just create partial view and call them as below:
and in your partial view use as below:
is working on a reply...