Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sam Aspin 11 posts 31 karma points
    Sep 24, 2013 @ 18:34
    Sam Aspin
    0

    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());
                     
                }
                quote = AvailableQuotes.Items[Model.ViewBag.CandidateQuoteID];  
            }

     

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Sep 24, 2013 @ 20:47
    Ali Sheikh Taheri
    1

    Hi Sam,

    why don't just create partial view and call them as below:

    @PageRender("partialviewname.cshtml", Model.Content)
    

    and in your partial view use as below:

    @model IPublishedContent
    
    <div>@Model.Name</div>
    
Please Sign in or register to post replies

Write your reply to:

Draft