Copied to clipboard

Flag this post as spam?

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


  • Dave Hermans 3 posts 23 karma points
    Aug 23, 2012 @ 10:45
    Dave Hermans
    0

    passing a template into a .Net macro

    Hi,

    I'm looking into a way of passing markup as a template into a .Net macro.

    Allow me to explain. For a car dealership i have a control that displays a list of cars from a backend system using a .Net control. This control is basicly a repeater control with some backend lookup logic (search, sort and paging ect).

    This works fine. However the way a single item is displayed (ItemTemplate in the repeater control) is set in the usercontrol. Now i woul like to reuse this control on other pages. But this would require me to change the template used in the ItemTemplate. Is there a clean way of doing this in a macro. I know i can pass it as a property, but this would be a mess since the template itself would contain singel and double qoutes and stuff.

    Anybody got any ideas?

  • Drew 165 posts 340 karma points
    Sep 04, 2012 @ 13:46
    Drew
    0

    As you said, one way is to pass the params in the macro call to your .NET control.

    The other way (although not the best) that springs to mind is to use an XSLT extension instead, whereby the extension returns the resulting HTML and you pass in params in the extension call itself. Again, not the prettiest method.

     

    How are you re-using the control on the page?

    One thing I've done a few times before is, in the code that supports your user control, to simply get the current node, check the DocType/alias, and if it matches a certain type of page, change the output from the View instead.
    (of course, when you have access to the current node, you can check all sorts of things and alter the output from your View accordingly - as well as access any properties on the doctype/page that you've created).

     

    Cheers, 

  • Dave Hermans 3 posts 23 karma points
    Sep 07, 2012 @ 12:06
    Dave Hermans
    0

    Drew, thanks for the reply.

    I'm reusing this control not only for a single site, but also for multiple sites, hopefully 100's of them in the future :)

    And as i stated in my OP, the HTML of a single item changes per site and even per page. My ideal solution would be to be able to just type the repeating html between the opening en closing tags of the macro, but i know this is not possible. So i'm looking for another way. The one thing i want to avoid is that i have to redeploy the user control for every site because the logic doesn't change, only the HTML does. And this would also be a nightmare to maintain when the number of sites increases.

    Another thing I was thinking of is to put the required HTML in some sort of container, a dictionary item or something and call this in the macro to get the HTML. Would this be a good solution?

    Again i'm open to any other solution because i'm not convinced this is the best way.

  • Drew 165 posts 340 karma points
    Sep 07, 2012 @ 14:21
    Drew
    0

    You could alway pass a property to the user control that defined the layout used by the template - like the name of a layout or theme you wanted to use. Then just check the value and render the content appropriately.

    This may mean though, if you have a lot of styles/layouts that you'll end up with a lot of logic in your user controls.

    Alternatively, use different user controls for the front-end display, that get their data and process it from a central library/DLL (so they're as thin as possible).

    If you're going to be using this logic across multiple sites (even into the hundreds) and if they'll all be using the same data source (e.g. the same database) then I'd actually suggest that you look at using a WCF service to grab your HTML/results from, as this would be more scalable and accessible.
    Then you can simply use a macro on each site that grabs the data (via a call to an XSLT Extension that gets the data from the webservice), and formats the data appropriately.

     

    I guess it boils down to:
    1. How many templates are you going to have overall
    2. Does the data in the control always come from the same data source?

    Cheers,
    Drew 

Please Sign in or register to post replies

Write your reply to:

Draft