Copied to clipboard

Flag this post as spam?

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


  • JacoboPolavieja 62 posts 84 karma points
    Jul 26, 2010 @ 10:43
    JacoboPolavieja
    0

    Limiting nodes (tags) to accomodate div's height

    Hello all again!

    Continuing with my page... I went through the umbraco.tv tutorial on the "Tags" datatype and all went pretty well.

    Now, the only problem I have is that after generating the Tags list I want to display them in some form of cloud on a div. The cloud part is also explained in the video, so that's great. The only problem left is the div's one. As lots of Tags are generated, the list is huge, and they surpass the div's height, resulting in tags being displayed beyond its limts and "polluting" other sections on the page.

    The list fits the div's width nicely... whenever they reach the maximum width, the list continues in the next line. The same doesn't apply height wise.

    Anyone knows an easy fix for this? I could limit the number of nodes displayed but as some tags are way longer than others, results may display a bit weird depending on the length of the tags.

    Thanks! Cheers!

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 26, 2010 @ 11:11
    Thomas Höhler
    0

    An easy 'fix' is to limit the output and append some dots or something else:

    Snippet

    <xsl:variable name="maxChar" select="30" />
    <xsl:choose> <xsl:when test="string-length(@nodeName) &lt; $maxChar> <xsl:value-of select="@nodeName" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="concat(substring(@nodeName, 1, $maxChar - 3), '...')" /> </xsl:otherwise> </xsl:choose>

    hth, Thomas

  • JacoboPolavieja 62 posts 84 karma points
    Jul 26, 2010 @ 12:29
    JacoboPolavieja
    0

    Hello Thomas and thanks for answering!

     

    Although that solution is neat it really doesn't solve the problem. I think I get you confused with the length ofthe tags part. The problem is not that the tags are long or shot but that as new tags are created, the surpass the height limit of the div. Even if I shorten them with you approach, the will keep going out of the div as far as the tags list goes.

    In short, what I need is to say... fill the space of this div with tags until there isn't room for one more, and don't go beyond there.

     

    Thank you anyway I'll keep that code for the future as it's interesting! Cheers!

     

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 26, 2010 @ 16:22
    Thomas Höhler
    0

    Ah, ok, then I recommend implementing an own XsltExtension which renders (and limits) the tags, like this one:

    Snippet

    public static string GetTags(int nodeId, int myMaxTagCount)
    {
        string tags = new umbraco.presentation.nodeFactory.Node(nodeId).GetProperty("MyTagAlias").Value;
        string[] tagArray = tags.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
        int maxTagCount = (tagArray.Length > myMaxTagCount ? myMaxTagCount : tagArray.Length);
                
        var sb = new StringBuilder();
        for (int i = 0; i < maxTagCount; i++)
        {
            // Rendering the tag how you would like to...
            sb.Append(tagArray[i]);
        }

        return sb.ToString();
    }

    hth, Thomas

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jul 26, 2010 @ 18:49
    Peter Duncanson
    0

    If you have a fixed height for your div why not let it scroll with some CSS?

    mydiv {
      overflow: scroll;
    }

    Quick fix?

  • JacoboPolavieja 62 posts 84 karma points
    Jul 26, 2010 @ 19:22
    JacoboPolavieja
    0

    Hello!

     

    Thank you both for your great answers! Peter, the overflow:scroll doesn't do the trick unfortunately asthe scroll bars where I have the tags div completely ruin the design. Anyway, I really didn't know about that css option... after googling for it I see "overflow: hidden;" does the trick! It still load all the tags and not just the ones which occupy the space, but visually wise, it goes perfect.

    About loading all the tags, I think Thomas' code may be perfect to achieve that, so I'll have a try at it. I don't know if the performance gain will be representative anyway.

     

    Thanks a lot! This forum is so helpful!

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 26, 2010 @ 19:32
    Thomas Höhler
    0

    Ther should be no problem with the performance cause the presentation.NodeFactory Namespace represents the date in memory as .NET objects. It should be fast enought. ;-)

    Thomas

  • JacoboPolavieja 62 posts 84 karma points
    Jul 26, 2010 @ 20:00
    JacoboPolavieja
    0

    Hehe! Thanks Thomas.

    I'd really prefer to code C# than XSLT, that's for sure... it's just that I read there could be perfomance issues. Then I read a blog post from the creator of LINQ to Umbraco and the doubts came again... By now I'm sticking with XSLT and once I have all up and running I will explore the world of C# with umbraco.

     

    Thanks a lot for helping. I'm all new to Umbraco and with the help of all of you I'm being able to pull this off! Cheers!

Please Sign in or register to post replies

Write your reply to:

Draft