Copied to clipboard

Flag this post as spam?

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


  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Aug 05, 2010 @ 00:50
    Nicholas Westby
    0

    Pass Multilanguage Custom Data Type as Macro Parameter

    I have an Umbraco website that uses multiple languages using the query string/session technique (i.e., the language code is specified in the query string and retained in the session state). To specify a property in a different language, I just create multiple properties (e.g., "pageTitle" and "pageTitle_zh-SG") and the XSLT macros are able to choose between the property based on the language code in the session state.

    My problem comes in when I try to pass a property created with a custom .Net data type to a .Net macro. In particular, I have an ASP.Net slideshow that I populate with data from a document property of a custom .Net data type. The template for this slideshow currently looks like this:

    <umbraco:Macro Alias="WebSlideshow" SlideXml="[#HomepageSlides]" runat="server" />

    The slideshow user control is called "WebSlideshow" and it has a property, "SlideXml", that is used to populate the slideshow data (XML containing image paths and such). It currently gets populated by the "HomepageSlides" document property, which is of a custom .Net data type. What I would like to do is choose between multiple languages for that slideshow data. So, I'd like a HomepageSlides, HomepageSlides_zh-SG, HomepageSlides_es-PE, and so on (one for each language). Then, I'd like to be able to choose between those using the session variable, "lang", and pass the result to the WebSlideshow.

    I've figured out a couple ways to do this (e.g., embed the language selection in the custom data type, have the WebSlideshow user control interact with the Umbraco API to choose the appropriate XML node), but they are all kind of clunky, so I'd like to see if there is a recommended approach for this situation.

  • Sascha Wolter 615 posts 1101 karma points
    Aug 05, 2010 @ 02:03
    Sascha Wolter
    0

    Hi Nicholas,

    I faced a similar situation not long ago. The properties to fetch were just textboxes and not custom .Net controls, but I guess the situation is pretty much the same: you want to get the data from the right property based on the current language, e.g. [#HomepageSlides_es] for Spanish, [#HomepageSlides_de] for German etc. in a dynamic fashion.

    The issue is like you said that you can't create the paramters inside of the macro tag dynamically as either they would't be set or otherwise the macro wouldn't be rendered. So in my solution I went for your second approach, providing the 'raw' property alias and retrieve the actual value to use in the .Net control based on the language, e.g.

    string Property {get;set;}
    string langExtension = (string)Session["langExtension"];
    Node n = Node.GetCurrent();
    string value = n.getProperty(Property + langExtension).Value;

    It's obviously a bit more work than for a single language site, however a couple of lines of code for dynamic selection isn't too bad in my view. Since none of the aliases are hard coded you have still full control over what you actually pass in to the control - only that you choose the alias instead of the actual value.

    If anyone has a better solution I'd like to hear that as well... :)

    Sascha

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Aug 05, 2010 @ 19:05
    Nicholas Westby
    0

    That's a pretty good idea. Unless anybody has any better ideas, I will go with that. Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft