Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Apr 17, 2014 @ 21:01
    Paul Griffiths
    0

    Select a specific check box item and display it

    Hello all,

    Yet again another xslt hurdle!

    I have a document type called venue which has a property called venueFeatures and that is of a custom data type that I created also called Venue Features (id=1133). It holds a list of prevalues such as

    Text Value

    VIP Upgrade 101

    WI-FI Access 102

    etc

    what I am trying to do in my code is.... If the checkbox value for wifi access is selected then I want to show the list item and apply the styles but if it is not checked i want it to reamin hiddden.

    I have tried the following but had no luck and was wondering if you can help please?

    <xsl:variable name="value" select="umbraco.library:GetPreValues('1133')"/>
    
    <div class="venue-search-features">
          <ul>
            <li class="title"><span>Venue Features:</span></li>
            <xsl:if test="$value/preValue[@alias='102'] = '1'"> 
            <li class="wifi" title="wifi"><span>WiFi</span></li>
            </xsl:if>
    
    <more list items here>
          </ul>
        </div
    

    I have done and it displays all the items in the datatype so i know im targeting the right thing.

    Been search around but no luck so Any help would be awesome please.

    Paul

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 17, 2014 @ 21:47
    Chriztian Steinmeier
    0

    Hi Paul,

    If I remember correct, the GetPreValues() extension just gives you the aliases ids and their corresponding text values (e.g., <preValue alias="102">Wi-Fi Access</preValue> <preValue id="102">Wi-Fi Access</preValue>) - so you can't know if it's checked there.

    If the venueFeatures property is configured to store the ids (aliases) you'll need to use the Split() extension to check that - but you might as well hardcode the Wifi ID, something like this (and if you need to "sync" the WiFi text shown, you can use the GetPreValues() extension to get the text for the wifi item):

    <xsl:variable name="wifiAlias" select="102" />
    <xsl:variable name="checkedFeatures" select="umbraco.library:Split($currentPage/venueFeatures, ',')" />
    <xsl:variable name="preValues" select="umbraco.library:GetPreValues(1133)" />
    <xsl:variable name="wifiText" select="$preValues/preValue[@id = $wifiAlias]" />
    
    <div class="venue-search-features">
        <ul>
            <li class="title"><span>Venue Features:</span></li>
            <xsl:if test="$checkedFeatures[value = $wifiAlias]">
                <li class="wifi" title="wifi">
                    <span><xsl:value-of select="$wifiText" /></span>
                </li>
            </xsl:if>
        </ul>
    </div>
    

    Oh, and if this doesn't work at all, I apologize in advance, as it's completely made up from memory (fingers crossed :) - it should show you the basics of how to use these extensions, though...

    EDIT: Changed to use id instead of alias as first assumed.

    /Chriztian

  • Paul Griffiths 370 posts 1021 karma points
    Apr 17, 2014 @ 22:26
    Paul Griffiths
    0

    Hi Christian,

    Thanks for your input mate. Ive been trying to do it with the help you provided but no luck just yet.

    I will let you know ;)

    Thanks

    Paul

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 17, 2014 @ 22:31
    Chriztian Steinmeier
    0

    Aha!

    Just checked the wiki... couldn't for the life of me figure out why they'd used alias attributes for those — turns out they didn't; they're id attributes, so the updated code should be:

    <xsl:variable name="wifiAlias" select="102" />
    <xsl:variable name="checkedFeatures" select="umbraco.library:Split($currentPage/venueFeatures, ',')" />
    <xsl:variable name="preValues" select="umbraco.library:GetPreValues(1133)" />
    <xsl:variable name="wifiText" select="$preValues/preValue[@id = $wifiAlias]" />
    
    <div class="venue-search-features">
        <ul>
            <li class="title"><span>Venue Features:</span></li>
            <xsl:if test="$checkedFeatures[value = $wifiAlias]">
                <li class="wifi" title="wifi">
                    <span><xsl:value-of select="$wifiText" /></span>
                </li>
            </xsl:if>
        </ul>
    </div>
    

    That should at least fix some of it...

    /Chriztian

  • Paul Griffiths 370 posts 1021 karma points
    Apr 17, 2014 @ 22:35
    Paul Griffiths
    0

    Ok tried it with @id instead but doesnt seem to be working either!

    hmmmm maybe its something ive done. but i also tried copying and pasting your code too.

    Ill keep tyring ;)

    Thanks mate

    Paul

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 17, 2014 @ 22:40
    Chriztian Steinmeier
    0

    OK,

    First thing:

    Copy the output of venueFeatures and the call to GetPreValues() to a textarea to do some sanity-checking:

    <textarea>
    <xsl:copy-of select="$currentPage/venueFeatures"/>
    ...
    <xsl:copy-of select="umbraco.library:GetPreValues(1133)" />
    </textarea>
    

    Then we'll figure out what's going on...

    /Chriztian

  • Paul Griffiths 370 posts 1021 karma points
    Apr 17, 2014 @ 22:51
    Paul Griffiths
    0

    Hi

    Here are the results from the test!

    <preValues><preValue id="94">PA System</preValue><preValue id="96">Late Bar License</preValue><preValue id="123">Private Bar</preValue><preValue id="97">AV Equipment</preValue><preValue id="98">Car Parking</preValue><preValue id="99">Accomodation</preValue><preValue id="100">Catering Facilities</preValue><preValue id="119">Own Catering Allowed</preValue><preValue id="101">VIP Upgrade</preValue>**<preValue id="102">WI-FI Access</preValue>**<preValue id="103">Greeting Staff</preValue><preValue id="104">Childrens Play Area</preValue><preValue id="105">Disabled Access</preValue><preValue id="106">Room Partitoning</preValue><preValue id="107">Baby Facilities</preValue><preValue id="108">Air Conditioning</preValue><preValue id="109">Seating Area</preValue><preValue id="110">Dance Floor</preValue><preValue id="111">Smoking Area</preValue><preValue id="112">Outdoor Area</preValue><preValue id="113">Stage Area</preValue><preValue id="114">Gymnasium</preValue><preValue id="115">Swimming Pool</preValue><preValue id="116">Sauna/Steam Room</preValue><preValue id="117">Hair &amp; Beauty Facilities</preValue><preValue id="118">DJ facilities</preValue><preValue id="120">Golf Course</preValue><preValue id="121">Suitable for Familys </preValue><preValue id="122">Outdoor Pursuits</preValue><preValue id="124">Media Equipment</preValue><preValue id="165">Dining Room</preValue><preValue id="166">Dry Cleaning</preValue></preValues>
    

    also the results from testing the variable values

        <xsl:value-of select="$wifiText" /> = WI-FI Access
        <xsl:value-of select="$checkedFeatures" /> = No Result
        <xsl:value-of select="$preValues" />PA SystemLate Bar LicensePrivate BarAV EquipmentCar ParkingAccomodationCatering FacilitiesOwn Catering AllowedVIP UpgradeWI-FI AccessGreeting StaffChildrens Play AreaDisabled AccessRoom PartitoningBaby FacilitiesAir ConditioningSeating AreaDance FloorSmoking AreaOutdoor AreaStage AreaGymnasiumSwimming PoolSauna/Steam RoomHair &amp; Beauty FacilitiesDJ facilitiesGolf CourseSuitable for Familys Outdoor
                 <xsl:value-of select="$wifiAlias" /> = 102
    

    Using the @id fetches back the correct values for $wiFiText and $wifiAlias

    Cheers mate

    Paul

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 17, 2014 @ 23:08
    Chriztian Steinmeier
    0

    Okay - great,

    So the venueFeatures are not showing anywhere - which means that either the property isn't called that (check the casing), you're testing on a page that hasn't got any features selected or you're testing a page that hasn't got the property at all...

    /Chriztian

  • Paul Griffiths 370 posts 1021 karma points
    Apr 17, 2014 @ 23:24
    Paul Griffiths
    0

    Hi Chriztian,

    I know have some values showing i think my logic is wrong somewhere.

    I will have a look into it and be in touch.

    Thnaks for your help again

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft