Copied to clipboard

Flag this post as spam?

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


  • dominik 711 posts 733 karma points
    Mar 18, 2011 @ 14:13
    dominik
    0

    Use Multi Tree Node picker for images

    Hello everybody.

    I want to develop a banner management tool.

    For this reason i created a new mediaType called "banner" which has some properties (file, width, height) and one property called "bannerShowOnPage" which is a MultiTree Node Picker.

    This Multi Tree Node picker selects some Content IDs where the banner should appear.

    How must the XSLT look like if i want to check if for the currentPage there is a banner? I cant get it work

    This is my XSLT right now (which does not work):

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:ucomponents.cms="urn:ucomponents.cms" xmlns:ucomponents.dates="urn:ucomponents.dates" xmlns:ucomponents.io="urn:ucomponents.io" xmlns:ucomponents.members="urn:ucomponents.members" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:ucomponents.urls="urn:ucomponents.urls" xmlns:ucomponents.xml="urn:ucomponents.xml" xmlns:tagsLib="urn:tagsLib" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
      exclude-result-prefixes="msxml
    umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes
    Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings
    Exslt.ExsltSets ucomponents.cms ucomponents.dates ucomponents.io
    ucomponents.members ucomponents.strings ucomponents.urls ucomponents.xml
    tagsLib umbraco.contour PS.XSLTsearch "
    >


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
      
      <xsl:if test="$currentPage/bannerShowOnPage/MultiNodePicker/nodeId">

              <!-- Loop through each of the nodeId values -->
          <xsl:for-each select="$currentPage/bannerShowOnPage/MultiNodePicker/nodeId">
             <p>Test</p>
            <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(.)" />
            <img src="{$node/umbracoFile}" alt="[image]" height="{$node/umbracoHeight}" width="{$node/umbracoWidth}" />

          </xsl:for-each>

          <br /><br />

      </xsl:if>
      
    </xsl:template>

    </xsl:stylesheet>
  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 18, 2011 @ 14:40
    Lee Kelleher
    0

    Hi Dominik,

    Try replacing the "GetXmlNodeById" line, with...

    <xsl:variable name="node" select="umbraco.library:GetMedia(., false())" />

    Cheers, Lee.

  • dominik 711 posts 733 karma points
    Mar 18, 2011 @ 14:49
    dominik
    0

    thanks but the problem is that the xslt does not go inside the if statement.

    so the first line:

    <xsl:if test="$currentPage/bannerShowOnPage/MultiNodePicker/nodeId">

    does not work.

    How can i get the image for the content i selected in the Multi Tree Note Picker.

    I think this is the problem

     

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 18, 2011 @ 15:00
    Tom Fulton
    0

    If I understand, your bannerShowOnPage MNTP field is actually on the Media Type and not the actual page/document, correct?

    If so that will be a bit more tricky, I think you'll have to loop through each media item in a given folder and look for the currentPage's ID in the bannerShowOnPage field.  Is that your situation?

  • dominik 711 posts 733 karma points
    Mar 18, 2011 @ 15:04
    dominik
    0

    yes you are right i need this property on the image and not on the document.

    So I need some help how to setup this. I think it would be great if I get this working.

    I want just to check for each currentPage if there is an image for this ID (from the selected MNTP values).

    Is there a way to handle this?

  • dominik 711 posts 733 karma points
    Mar 18, 2011 @ 15:09
    dominik
    0

    just to explain what i want to realise:

    I add an image an choose via MNTP the content where it should appear. So a banner can be shown on selected pages without beeing added to each content from the content section.

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 18, 2011 @ 15:24
    Tom Fulton
    1

    Hi,

    Here's a down-and-dirty way to do it:

    <xsl:variable name="mediaFolderId" select="1127"/> <!-- replace 1127 with the ID of your folder that contains the banners -->

    <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/banner">  <!-- replace "banner" with your media type alias -->
      <xsl:variable name="mediaNode" select="."/>
      
      <xsl:for-each select="./bannerShowOnPage/MultiNodePicker/nodeId">
        <xsl:if test=". = $currentPage/@id">
          <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{$mediaNode/umbracoHeight}" width="{$mediaNode/umbracoWidth}" />
        </xsl:if>
      </xsl:for-each>
      
    </xsl:for-each>

    This could probably be optimized a bit.  I was trying to avoid the second for-each loop with something like <xsl:if test="count(./bannerShowOnPage/MultiNodePicker/* [nodeId = $currentPage/@id]) &gt; 0"> but couldn't get that working.

    Hope this helps,
    Tom

     

  • dominik 711 posts 733 karma points
    Mar 18, 2011 @ 15:31
    dominik
    0

    Thanks

    But if i choose a folder with the MNTP the banner is not shown in all of the child pages. How can i get this also working?

    For example if i choose the root node the banner is shown on all sub nodes

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 18, 2011 @ 15:39
    Tom Fulton
    0

    So if you choose About Us, you want the banner to show on all subpages of About Us also?

    Try changing

        <xsl:if test=". = $currentPage/@id">

    to

        <xsl:if test=". = $currentPage/ancestor-or-self::* [@isDoc]/@id">

    -Tom

  • dominik 711 posts 733 karma points
    Mar 18, 2011 @ 16:01
    dominik
    0

    ok it works,

    thanks for your help.

    Now i have got the next question :-)

    I just tried to use a URL and it works - i create a property (textstring) for an external url (bannerExternalLink)

    Now i want also to create a content picker for internal links (property "bannerInternalLink"). If the bannerInternalLink is != "" it should use this otherwise he should use the bannerExternalLink

    THis is how my externalLink is working until now:

    <a href="{$mediaNode/bannerExternalLink}" target="{$mediaNode/bannerLinkTarget}"><img src="{$mediaNode/umbracoFile}" alt="[image]" height="{$mediaNode/umbracoHeight}" width="{$mediaNode/umbracoWidth}" /></a>
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 18, 2011 @ 16:06
    Tom Fulton
    0

    Hi,

    You can determine the href attribute with a choose statement, like so:

    <a href="#" target="{$mediaNode/bannerLinkTarget}">
        <xsl:attribute name="href">
            <xsl:choose>
                <xsl:when test="string($mediaNode/bannerInternalLink) != ''">
                    <xsl:value-of select="umbraco.library:NiceUrl($mediaNode/bannerInternalLink)"/>
                </xsl:when>
                <xsl:when test="string($mediaNode/bannerExternalLink) != ''">
                    <xsl:value-of select="$mediaNode/bannerExternalLink"/>
                </xsl:when>
            </xs:choose>
        </xsl:attribute>
        <img src="{$mediaNode/umbracoFile}" alt="[image]" height="{$mediaNode/umbracoHeight}" width="{$mediaNode/umbracoWidth}" />
    </a>

    Also, I might suggest using the URL Picker datatype from uComponents to simplify selecting the link for your content editors, it's one datatype that allows the editor to select internal/external/media/upload (you can control what options they can select), add a caption and check whether it should open in a new window.

    -Tom

  • dominik 711 posts 733 karma points
    Mar 18, 2011 @ 16:11
    dominik
    0

    Thanks - it works great

    I think i will come back to you if there are some more question.

    Hope this is ok? :-)

  • dominik 711 posts 733 karma points
    Mar 22, 2011 @ 08:23
    dominik
    0

    Ok now i have got another question:

    I added a new property called "position". This can have values like "footer, skyscraper, header" for example.

    Now i want to check if there is one of the position "footer" and only show the banner with this position. i think i must put an if statement arround all of my xslt code? is this correct.

    Perhaps you can help once again :-)

     

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 22, 2011 @ 13:45
    Tom Fulton
    0

    Hi dominik,

    You can add this condition in your original for-each loop, ex:

    <xsl:for-each select="umbraco.library:GetMedia($mediaFolderId, true())/banner [position = 'footer']">

    -Tom

  • dominik 711 posts 733 karma points
    Mar 22, 2011 @ 14:08
    dominik
    0

    Thanks

    I now try to integrate a show from until field.

    I got it working via this xslt:

    <xsl:if test="$pos
    = $mediaNode/bannerSetPosition and
    umbraco.library:DateGreaterThanOrEqual($today, $datestart) and
    umbraco.library:DateGreaterThanOrEqual($dateend, $today)"
    >

    What is the best method to only use this statement if there is filled out a date. If there is no date selected it should be shown all of the time.

  • dominik 711 posts 733 karma points
    Mar 22, 2011 @ 14:58
    dominik
    0

    ok I think i get it working by simply putting some "or" functionality inside the if statement.

  • dominik 711 posts 733 karma points
    Mar 22, 2011 @ 15:48
    dominik
    0

    I just tryed to use the sort function of umbraco to put some banners to the top of the list (if there is more then one banner for the position). But this was not working.

    Here is my xslt

    <xsl:sort select="@sortOrder" order="descending" data-type="number"/>

     

    Is there a possibility of using the umbraco backend sort functionallity to display the banners?

     

  • dominik 711 posts 733 karma points
    Apr 18, 2011 @ 10:24
    dominik
    0

    Hi i just updated to version 4.7 but the sort function for media item still not work.

    I want to display the media item with the lowest sort order id at the top.

    Anyone any solution for this problem?

Please Sign in or register to post replies

Write your reply to:

Draft