Copied to clipboard

Flag this post as spam?

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


  • Stephen Davidson 216 posts 392 karma points
    Feb 23, 2015 @ 17:54
    Stephen Davidson
    0

    Display content from MultiPicker Relations in Template

    Finally got my head round MultiPicker Relations and how I can use them to get the Many to Many relationship I need, as dicussed in this forum post.

    I cant seem to find any examples of how i would display the content which has been selected (via the picker) in a template.

    As with most things i would want to display an overview and a detail view of the selected items.

    S

  • Jan Skovgaard 11264 posts 23594 karma points MVP 9x admin c-trib
    Feb 23, 2015 @ 18:30
    Jan Skovgaard
    1

    Hi Stephen

    Don't know if this article can help a bit http://24days.in/umbraco/2012/who-picked-this/

    But you should be able to retrieve some data by rendering the name of your relationspicker alias, which you have setup on the document type I guess?

    /Jan

  • Stephen Davidson 216 posts 392 karma points
    Feb 24, 2015 @ 10:38
    Stephen Davidson
    0

    Thanks (again!) Jan...

    S

  • Jan Skovgaard 11264 posts 23594 karma points MVP 9x admin c-trib
    Feb 24, 2015 @ 21:58
    Jan Skovgaard
    0

    Hi Stephen

    You're welcome - Did it help any?

    /Jan

  • Stephen Davidson 216 posts 392 karma points
    Feb 25, 2015 @ 18:13
    Stephen Davidson
    0

    Not sure yet...trying it out tonight...not enough time in the daytime!

  • Stephen Davidson 216 posts 392 karma points
    Feb 25, 2015 @ 21:26
    Stephen Davidson
    0

    ok made some progress tonight...i have the vacancy displaying the ID's of the candidates that I have associated via teh relaion pickers. Show below. From here I am usure how to display the properties of the candidate and link through to a detail page..

     

     

     

     

     

     

  • Jan Skovgaard 11264 posts 23594 karma points MVP 9x admin c-trib
    Feb 25, 2015 @ 21:33
    Jan Skovgaard
    0

    Hi Stephen

    What does your current code look like? You will need to get the content by the id in the comma seperated list. So you will probably need to Split the string that returns the id's and then loop over each of the id's and fetch the content based on the id.

    Depending on whether you're using Dynamic Razor or Strongly typed you need to use either @Umbraco.Content() or @Umbraco.TypedContent() - You can probably benefit from using the Razor cheat sheet here https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

    Hope this helps.

    /Jan

  • Stephen Davidson 216 posts 392 karma points
    Feb 25, 2015 @ 21:53
    Stephen Davidson
    0

    Not sure if this is what you mean...I'm using 6.1.3 and have a mix od razor and XSLT but will probably opt for Razor on this one.

  • Jan Skovgaard 11264 posts 23594 karma points MVP 9x admin c-trib
    Feb 25, 2015 @ 21:57
    Jan Skovgaard
    0

    Hi Stephen

    I'm mean the code...which you use to render the view you posted a screendump of in your previous post - It will help to see your XSLT/Razor code :)

    What version of Umbraco are you using btw?

    /Jan

  • Stephen Davidson 216 posts 392 karma points
    Feb 25, 2015 @ 22:13
    Stephen Davidson
    0
    <%@ Master Language="C#" MasterPageFile="~/masterpages/umbMaster.master" AutoEventWireup="true" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="cp_content" runat="server">
        <div class="row">
            <div class="col-lg-9">
                <div id="content" class="textpage">
    
                    <div id="contentHeader">
                        <a href="../" class="btn pull-right" ><i class="fa fa-chevron-left"></i> Back to all jobs</a>
                        <h2>
                            <umbraco:Item ID="Item1" runat="server" Field="pageName" />
                        </h2>
                    </div>
    
                    <umbraco:Item ID="Item2" runat="server" Field="bodyText" />
                    <h2>Candidates</h2>
    
                    <umbraco:Item field="candidates" runat="server" />
    
                    <umbraco:Item field="cVContents" runat="server" />
    
                    <umbraco:Item field="candidateName" runat="server" />
    
    
    
                </div>
    
            </div>
    
    
        </div>
    
    
    
    
    </asp:Content>
    Only this line displays the ID's
     <umbraco:Item field="candidates" runat="server" />
     
  • Jan Skovgaard 11264 posts 23594 karma points MVP 9x admin c-trib
    Feb 25, 2015 @ 22:37
    Jan Skovgaard
    0

    Hi Stephen

    Ok, well that is expected as well since it's only the ID's that are stored in the "candidates" filed and you'll then need to look them up as I described above.

    I have not been using the MultiPicker relations picker myself so I don't know what it returns XML wise if you choose to render it using XSLT. But I suspect it may just return a comma seperated list of the id's...

    so in XSLT you should be able to do something like

    <!-- Let's fetch the id's -->
    <xsl:variable name="ids" select="umbraco.library:Split($currentPage/candidates,',')" />
    

    Now that you have split the id's then you should be able to loop over the returned

    Does this make sense? Or do you need a bit more in order to get started - This should of course be written in an XSLT macro :)

    /Jan

  • Stephen Davidson 216 posts 392 karma points
    Feb 25, 2015 @ 22:46
    Stephen Davidson
    0

    Yip great info, I'll report back with the result.

    S

  • Jan Skovgaard 11264 posts 23594 karma points MVP 9x admin c-trib
    Feb 25, 2015 @ 22:57
    Jan Skovgaard
    0

    Sounds good Stephen, looking forward to see what you come up with :)

    /Jan

  • Stephen Davidson 216 posts 392 karma points
    Feb 26, 2015 @ 18:08
    Stephen Davidson
    101

    Here is the finished code if anyone is interested.. really enjoyed finding out about relations in Umbraco...all new to me and pretty powerfull. Even managed to combine the UMB Vimeo video picker into the code. Inspired me to write a blog post about how to do this as there are very few exmaples of how to use relations etc out there.

    <?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:Examine="urn:Examine" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:ucomponents.cms="urn:ucomponents.cms" xmlns:ucomponents.dates="urn:ucomponents.dates" xmlns:ucomponents.email="urn:ucomponents.email" xmlns:ucomponents.io="urn:ucomponents.io" xmlns:ucomponents.media="urn:ucomponents.media" xmlns:ucomponents.members="urn:ucomponents.members" xmlns:ucomponents.nodes="urn:ucomponents.nodes" xmlns:ucomponents.random="urn:ucomponents.random" xmlns:ucomponents.request="urn:ucomponents.request" xmlns:ucomponents.search="urn:ucomponents.search" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:ucomponents.urls="urn:ucomponents.urls" xmlns:ucomponents.xml="urn:ucomponents.xml" 
        xmlns:vimeo="urn:vimeo" 
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets Examine tagsLib BlogLibrary ucomponents.cms ucomponents.dates ucomponents.email ucomponents.io ucomponents.media ucomponents.members ucomponents.nodes ucomponents.random ucomponents.request ucomponents.search ucomponents.strings ucomponents.urls ucomponents.xml vimeo ">
    
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
    
                    <!-- Let's fetch the id's -->
                    <xsl:if test="string-length($currentPage/candidates) > 0">  
                      <xsl:variable name="items" select="umbraco.library:Split($currentPage/candidates,',')" />  
    
                          <xsl:for-each select="$items//value">
                            <xsl:variable name="currentnode" select="umbraco.library:GetXmlNodeById(.)" />
                            <!-- render only published nodes -->
                            <xsl:if test="count($currentnode/error) = 0">
    
                                <div class="col-md-3 videoPanelSml">
                                     <h3><a href="{umbraco.library:NiceUrl($currentnode/@id)}" ><xsl:value-of select="$currentnode/candidateName" /></a></h3>
                                     <xsl:if test="string-length($currentnode/videoEmbed) &gt; 0"> 
                                        <iframe src="//player.vimeo.com/video/{$currentnode/videoEmbed}" width="250" Height="130" frameborder="0"></iframe>
                                        <xsl:variable name="item" select="vimeo:GetMedia($currentnode/videoEmbed/value/@dataTypeId, $currentnode/videoEmbed/value)" />
                                        <xsl:value-of select="$item/EmbedCode" disable-output-escaping="yes" />
                                     </xsl:if>
                                     <a href="{umbraco.library:NiceUrl($currentnode/@id)}" class="btn btn-xs btn-block" >View details </a>
                                </div>
    
                            </xsl:if>                       
                          </xsl:for-each>
    
                    </xsl:if>
    
    </xsl:template>
    
    
    </xsl:stylesheet>

    Which gives me the following result. Looking to now extend this to inculude the ability to "like" or "Favourite" a candidate again using relations in some way.

     

  • Jan Skovgaard 11264 posts 23594 karma points MVP 9x admin c-trib
    Feb 26, 2015 @ 18:16
    Jan Skovgaard
    1

    Hi Stephen

    Happy to see you managed to get it all working and awesome that you want to blog about it too :)

    Remember to mark the issue as solved as well.

    Happy writing (The blogpost)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft