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?
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 n in siteRoot.Descendants("FAQ").Where("Visible")) { <h4>@n.PageHeading - @tag</h4> } } </div> }
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.
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?
Please state the version of your Umbraco instance. (in this case it'll matter quite a bit)
sorry, using 4.7.1 -- thanks
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>
}
}
}
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...
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.
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!]
is working on a reply...