Copied to clipboard

Flag this post as spam?

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


  • Brian Olsen 143 posts 424 karma points
    Mar 06, 2013 @ 10:40
    Brian Olsen
    0

    Multitype datatype simple script to frontend

    Hi

    I use umbraco 4.11.5

    I am trying to use MultiType data type but can not get it to work in frontend

    it works in the backend of umbraco with this XLST script

    <xsl:param name="currentPage"/>

    <xsl:param name="Name" />

    <xsl:param name="Alias" />

    <xsl:param name="Value" />

    <xsl:param name="SortOrder" />

     

    <xsl:template match="/">

     <xsl:if test="$Name = 'Billede'">

    <xsl:variable name="mediaId" select="number($Value)" />

    <xsl:if test="$mediaId > 0">

            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />

            <xsl:if test="$mediaNode/umbracoFile">

                <img src="{$mediaNode/umbracoFile}" height="15%"/>

            </xsl:if>

    </xsl:if>

    </xsl:if>

    <xsl:if test="$Name != 'Billede'">

    <span class="value">

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

    </span>

     </xsl:if>

      <xsl:text> </xsl:text>

     

    where you can find some example of xslt or razor script to frontend

  • aghy 129 posts 308 karma points
    Mar 06, 2013 @ 11:18
    aghy
    100

    Hi Brian,

    To have a look at the structure created by the multitype try this:

    <umbraco:Item field="multiTypeTest" runat="server" />

    You wont see anything on the page but take a look at the source you should see something like:

    <items>
      <item id="1" sortid="1">
        <heading><!--[CDATA[Ben]]--></heading>
        <text><!--[CDATA[Hello]]--></text>
      </item>
      <item id="2" sortid="1">
        <heading><!--[CDATA[Tom]]--></heading>
        <text><!--[CDATA[Goodbye]]--></text>
      </item>
    </items>

    Obviously with your data inside, then you can use some razor on the page like:

    <umbraco:Macro runat="server" language="cshtml">
    @{
      foreach (dynamic item in Model.multiTypeTest)
      {
        <h2>@item.heading</h2>
        <p>@item.text</p>
      }
    }
    </umbraco:Macro>

    Where Model.multiTypeTest matches whatever the name of your multitype property is on the document type.

    Hopefully this makes sense and you can adapt it to work for you, any problems just let me know.

    Thanks
    Ben

  • Brian Olsen 143 posts 424 karma points
    Mar 06, 2013 @ 11:58
    Brian Olsen
    0

    thanks it was just what I needed :-)

Please Sign in or register to post replies

Write your reply to:

Draft