Copied to clipboard

Flag this post as spam?

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


  • bob baty-barr 1180 posts 1294 karma points MVP
    Mar 27, 2012 @ 00:57
    bob baty-barr
    0

    razor and contains

    i am trying the best i can to learn how to use razor code moving forward, but i am stuck with making something like this razor friendly.

    basically, i have a checkbox list as a property on every page... to show faqs that match these categories. then on each faqItem i have the same property to assign what category the faqs are in... this is so i can display category appropriate faqs... r u still with me? :) basically, i would like to convert this xslt to razor... any takers?

    <xsl:variable name="tags" select="umbraco.library:Split($currentPage/fAQTags,',')" />
      <xsl:call-template name="faqList">
        <xsl:with-param name="tagList" select="$tags"/>
      </xsl:call-template>
    </xsl:template>    
    <xsl:template name="faqList">
      <xsl:param name="tagList"/>
      <xsl:variable name="siteRoot" select="umbraco.library:GetXmlNodeById(1082)" />
      <!--
      <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
      -->
      <xsl:variable name="documentTypeAlias" select="string('FAQ')"/>
      <xsl:if test="$tagList !=''">
        <h3>Frequently Asked Question (FAQ)</h3>
          <div id="faqList">
      <xsl:for-each select="$tagList/value">
        <xsl:variable name="tag" select="." />
        <xsl:for-each select="$siteRoot//*[@isDoc and name() = $documentTypeAlias][not(umbracoNaviHide = 1)][contains(fAQTags, $tag)]">
                  <div><h4><xsl:value-of select="pageHeading"/></h4>
                    <p><xsl:value-of select="bodyText" disable-output-escaping="yes"/></p></div>
        </xsl:for-each>
      </xsl:for-each>
            <p><href="/faqs.aspx">View All FAQs&nbsp;&#187;</a></p></div>
        </xsl:if>
  • Grant Thomas 291 posts 324 karma points
    Mar 27, 2012 @ 01:23
    Grant Thomas
    0

    Please state the version of your Umbraco instance. (in this case it'll matter quite a bit)

  • bob baty-barr 1180 posts 1294 karma points MVP
    Mar 27, 2012 @ 15:37
    bob baty-barr
    0

    sorry, using 4.7.1 -- thanks

  • Sean Dooley 289 posts 528 karma points
    Mar 27, 2012 @ 16:23
    Sean Dooley
    1

    Off the top of my head, maybe something like the following

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      var tags = Model.Tags.Split(',');
      var siteRoot = Model.AncestorOrSelf(1);
      foreach(var tag in tags) {
        foreach(var node in siteRoot.Descendants("FAQ").Where("Visible && fAQTags.Contains(\"" + tag + "\"") {
          <div>
            <h4>@node.PageHeading</h4>
            @node.BodyText
          </div>
        }
      }
    }

  • bob baty-barr 1180 posts 1294 karma points MVP
    Mar 27, 2012 @ 17:10
    bob baty-barr
    0

    we are getting close for sure... but something is not quite right... been stepping through and cannot get things to save with the part about the contains... can we do a contains against a picker? I can get this to loop through and show the faqs and the tag associated... but i cannot get it to match the end page fAQTags...

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
      
      var siteRoot Model.AncestorOrSelf(1);
      var tags Model.fAQTags.Split(',');
      
    <h3>Frequently Asked Question (FAQ)</h3>
    <div id="faqList">
      @foreach(var tag in tags{
        foreach(var in siteRoot.Descendants("FAQ").Where("Visible"){
          <h4>@n.PageHeading @tag</h4>
        }
      }
      </div>
      
    }
  • Sean Dooley 289 posts 528 karma points
    Mar 28, 2012 @ 17:12
    Sean Dooley
    1

    Hi Bob

    Put together a quick sample myself in Umbraco 4.7.1.1 (hopefully works with your version). Think it matches up to what you are trying to do.

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
    string[] tags = Model.Tags.Split(',');
    foreach(var node in Model.AncestorOrSelf().Descendants("FAQ").Where("Visible && Tags.ContainsAny(@0)", tags))
    {
    <p>@node.Name | @node.Tags</p>
  • bob baty-barr 1180 posts 1294 karma points MVP
    Mar 28, 2012 @ 17:30
    bob baty-barr
    0

    Sean, you are a freakin' ROCK STAR!!!!

    thank you so much for working through this exercise with me! this gives me some insight into this razor coding with some practical application! crazy how brief the syntax is with razor vs. the old XSLT.

     

    a big #HFYR [high five you rock!]

Please Sign in or register to post replies

Write your reply to:

Draft