I am trying to loop through a checkbox datatype on a template page, however it will not return any results. Not really sure the best way to go about it. If I use umbraco:Item, it returns a comma listing of the boxes that are checked in the datatype, which is not terribly useful.
However, personally, I always stand out against this approach. For my taste using inline macros sounds like mixing presentation (templates) with logic (macro code). I'd better write the same down to the usual separate macro and put in into the template through its alias.
Yes, I'm aware of it. Afaik also Xslt can also be embeded into an <umbraco:Item> control through the Xslt property, however I've never used it. It doesn't matter anyway - as I said above for me it looks hideous in both cases :-)
Loop through datatype on template page
I am trying to loop through a checkbox datatype on a template page, however it will not return any results. Not really sure the best way to go about it. If I use umbraco:Item, it returns a comma listing of the boxes that are checked in the datatype, which is not terribly useful.
<umbraco:Item field="departmentOptions" stripParagraph="true" runat="server"></umbraco:Item>
this returns: Upcoming Events,Department Services,Our Staff
Trying to use XSL does not return anything:
<xsl:for-each select="umbraco.library:GetPreValues(departmentOptions)//preValue">
value: <xsl:value-of select="." /><br/>
</xsl:for-each>
Hi,
Did you try $currentPage/departmentOptions? If you're not already inside a loop or match template you'll want to prepend $currentPage.
-Tom
Im on a template page, not an an xslt doc. How do you use $currentPage on a template?
Hi, Jeremy. If you very much want to get it straight into template along with some transformation you can do it with an inline macro.
For instance like this:
However, personally, I always stand out against this approach. For my taste using inline macros sounds like mixing presentation (templates) with logic (macro code). I'd better write the same down to the usual separate macro and put in into the template through its alias.
Btw Rodion's example only works for Razor, not XSLT. If you want inline XSLT you need to download this package: http://our.umbraco.org/projects/backoffice-extensions/xslt-macro-engine
Jeroen
Yes, I'm aware of it. Afaik also Xslt can also be embeded into an <umbraco:Item> control through the Xslt property, however I've never used it. It doesn't matter anyway - as I said above for me it looks hideous in both cases :-)
I also prefer XSLT in a macro :). Just wanted to point out there was another option to use XSLT.
Jeroen
this is by no means pretty, but I ended up doing this:
<%
var boxes = umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("departmentOptions").Value;
string[] boxArray = boxes.Split( ',' );
if(boxArray.Contains("Upcoming Events")){ %>
<umbraco:Macro Alias="Department_UpcomingEvents" runat="server" />
<% } %>
is working on a reply...