Copied to clipboard

Flag this post as spam?

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


  • raghavendran 30 posts 50 karma points
    Aug 04, 2010 @ 10:19
    raghavendran
    0

    pass xslt o/p to .net user control

    i have the lang_lib.xslt which returns $flang for the localization in my code....i want to pass this $flang as a .net control parameter too so that i can alo localize my .net content based on the query...The thing is $flang is a variable in xslt and how will i get that variable to put it as a parameter in a .net control./...it is also impossible to compile a .net macro inside xslt...so please help me!!

  • Sascha Wolter 615 posts 1101 karma points
    Aug 04, 2010 @ 10:59
    Sascha Wolter
    0

    Hi raghavendran,

    have a look at this: http://umbraco.org/documentation/books/macro-parameters-syntax/advanced-parameter-syntax.

    So in order to pass in a language identifier that is e.g. held in the cookie you could do something like this:

    <umbraco:Macro langId="[%langid]" Alias="Login" runat="server"></umbraco:Macro>

    To my knowledge you cannot compile a .Net macro inside Xslt, that just won't work. You could though render another page template which has a .Net control on it, that should work.

    Sascha

  • Josh Townson 67 posts 162 karma points
    Aug 04, 2010 @ 11:31
    Josh Townson
    0

    Hi raghavendran, we do this just putting it into the Session, and a cookie for later - I think this is part of the standard lang.xslt file you are talking about:

    <xsl:template name="setlang">
    <xsl:value-of select="umbraco.library:setSession('lang',$lang)"/>
    <xsl:value-of select="umbraco.library:setCookie('lang',$lang)"/>
    </xsl:template>

    That pushes the value of $lang which is set somewhere in the file ;) Then in our language abstraction class we have the following function:

    private static int langid()
    {
    if (_languageCodes == null)
    {
    Language[] languages = Language.getAll;
    Dictionary<string, int> languageCodes = new Dictionary<string, int>();
    foreach (Language language in languages)
    {
    languageCodes.Add(language.CultureAlias.Substring(0, 2), language.id);
    }
    _languageCodes = languageCodes;
    }
    // Getting the language from the session will fail if this method is called from within a thread, so we need to use a try catch to supress that
    string lang = "";
    try
    {
    lang = umbraco.library.Session("lang");
    }
    catch {}
    if (lang != "")
    {
    if (_languageCodes.ContainsKey(lang))
    return _languageCodes[lang];
    }
    if (_dafaultLanguageId == -1)
    {
    string code = System.Configuration.ConfigurationManager.AppSettings["DefaultLanguageId"];
    if (code == null)
    {
    throw new System.Configuration.ConfigurationErrorsException("DefaultLanguageId app setting is missing");
    }
    if (!int.TryParse(code, out _dafaultLanguageId))
    {
    throw new System.Configuration.ConfigurationErrorsException("DefaultLanguageId app setting is not a number");
    }
    }
    return _dafaultLanguageId;
    }

    Which pulls out a lnaguage id from Umbraco (I think), which we use for getting the language name, and then pulling things out of the dictionary with that!

    /Josh

Please Sign in or register to post replies

Write your reply to:

Draft