Copied to clipboard

Flag this post as spam?

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


  • doruk 3 posts 23 karma points
    May 06, 2012 @ 02:34
    doruk
    0

    GetMedia in Site

    i have a macro;

      <xsl:param name="currentPage"/>
       
        <xsl:variable name="mediaId" select="number($currentPage/ancestor-or-self::Section/stockImage)"/>
        <xsl:template match="/">     
          <xsl:if test="$mediaId &gt; 0">
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 'false')" />
            <xsl:if test="$mediaNode/umbracoFile">
                <img src="{$mediaNode/umbracoFile}" alt="[image]" width="241px"/>
            </xsl:if>     
          </xsl:if>      
        </xsl:template>

    like this it is working in visualizer but not working in the site? when I addd this;

     

    <div>node:

            <xsl:value-of select="$currentPage/@nodeName"/><br />

            section nodename:

            <xsl:value-of select="$currentPage/ancestor-or-self::Section/@nodeName"/><br />

            media id:

            <xsl:value-of select="$mediaId"/><br />

            media:

            <xsl:copy-of select="umbraco.library:GetMedia($mediaId, 'false')"/><br />

          </div>

    to my macro

    nodename,section node and media id is correct but getMedia is not working? Any friend knows why?

     

  • doruk 3 posts 23 karma points
    May 06, 2012 @ 10:47
    doruk
    0

    H I solved the problem;

    if (VALID_ALIAS_CHARACTERS.Contains(currentChar.ToLower()))
    

     

    in turkish language it converts /Image to /mage but umbraco local is in default english so visualizer is working :D

    I changed the code to this;

    VALID_ALIAS_CHARACTERS.Contains(currentChar.ToLower(new System.Globalization.CultureInfo("en-US"))
    

    for now :D if this happens someone else, I can send new release binaries to him (if the one doesnt wantto edit code himself :D )

     

    Have a nice day

     

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 06, 2012 @ 11:19
    Chriztian Steinmeier
    0

    Hi doruk,

    Just out of curiosity - what was the real problem here? Have you renamed the Image Media Type using the Turkish I, or is it happening because your keyboard layout use the turkish letter (so your XPaths are using it by default)?

    Where does the code you've changed run? (E.g., does it run when you save a Media Type?)

    I'd like to understand this, as XML is perfectly capable of using almost any character set for elements, so the turkish I should not really be an issue...

    /Chriztian 

  • doruk 3 posts 23 karma points
    May 06, 2012 @ 12:28
    doruk
    0

    Oh hi,

     

    actual problem is i writed nothing in turkish , when solving xpath ;

    private static XPathNodeIterator getMediaDo(int MediaId, bool Deep)
            {
                Media m = new Media(MediaId);
                if (m.nodeObjectType == Media._objectType)
                {
                    XmlDocument mXml = new XmlDocument();
                    mXml.LoadXml(m.ToXml(mXml, Deep).OuterXml);
                    XPathNavigator xp = mXml.CreateNavigator();
                    string xpath = UmbracoSettings.UseLegacyXmlSchema ? "/node" : String.Format("/{0}"Casing.SafeAliasWithForcingCheck(m.ContentType.Alias));
                    return xp.Select(xpath);
                }
                return null;
            }

     Casing.SafeAliasWithForcingCheck(m.ContentType.Alias) --> this tries to solve '/Image' but in turkey;
     public static string SafeAlias(string alias)         {             StringBuilder safeString = new StringBuilder();             int aliasLength = alias.Length;             for (int i = 0; i < aliasLength;i++ )             {                 string currentChar = alias.Substring(i, 1);                 if (VALID_ALIAS_CHARACTERS.Contains(currentChar.ToLower()))                 {                     if (safeString.Length == 0 && INVALID_FIRST_CHARACTERS.Contains(currentChar.ToLower()))                     {                         currentChar = "";                     }                     else                     {                         if (i < aliasLength - 1 && i > 0 && alias.Substring(i - 1, 1) == " ")                             currentChar = currentChar.ToUpper();                         safeString.Append(currentChar);                     }                 }             }

    currentChar.ToLower() converts I to '' not i so it is not an allowed char (VALID_ALIAS_CHARACTERS) so it converts /Image to /mage hehe so i cant query and /Image type :D so I changed it to;
    currentChar.ToLower(new System.Globalization.CultureInfo("en-US"))
    and I am not using any turkish chars becouse I have no Turkish customer :D (all are Dutch or American :) )

    for my thought safeAliasculture must be a parameter in umbracoconfig :D
Please Sign in or register to post replies

Write your reply to:

Draft