I'm working on a doc type which has a lot of tabs with properties underneath. What I would like to do is be able to iterate through the tabs and write out the property name & alias of each property under a tab (With the tab name as a header)
Is this possible in XSLT or would I have to write some custom code using the API? I can see in the database that properties are linked to a tabId but can't find out how to use this data.
This is for produces filtering options for a product listing page - i.e. Tab Name - Ingredients would have ten properties I which to write out to screen.
This data is not available in XSLT. If you do want to use it you should create an xsltextension.
It would be easier to just write the headers yourself and then iterate the properties. If you want to know what information is available check /data/umbraco.config.
you can't access the tab-info in XSLT, simply because that isn't stored in the cache. Look at the umbraco.config file to see what info is there (that's the file that gets cached and that info you can access with xslt.
Do the tabs change frequently? If not, you might want to place them in the xslt (hardcoded). You define them in the document-type, so you know which tabs you added there. At least, that's the way I should do it, takes the least amount of effort and no need for custom code, which keeps it fast.
If you must access the data, you'd need to create custom code. This means that you have to make DB-calls each time a visitor accesses a page. Take a look at Doc2Form. That creates a dynamic form of a document-type and accesses tab-data as well.
Ron - I did think about starting the alias with the tabName (not nice I agree) but couldnt figure out how to do wildcards in XSLT - i.e. Search for tabName_*
using System; using System.Collections.Generic; using System.Text; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic; using System.Xml; using System.Xml.XPath; using umbraco.presentation.nodeFactory; using System.Web; namespace Umbraco.XSLTExtensions { public class Document { public static XPathNodeIterator GetPropertiesForDocumentTypeByTab(int DocumentTypeID, string TabAlias) {
XmlDocument xd = createDocument("properties"); DocumentType dt = new DocumentType(DocumentTypeID); int i = 1; foreach (ContentType.TabI t in dt.getVirtualTabs) { if (t.Caption == TabAlias) { foreach (umbraco.cms.businesslogic.propertytype.PropertyType pt in t.PropertyTypes) { XmlNode n = createResultNode(xd); n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "name", pt.Name)); n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "propertyAlias", pt.Alias)); n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "group", pt.Description)); n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "id", i.ToString())); xd.DocumentElement.AppendChild(n); i++; } } }
XPathNavigator xp = xd.CreateNavigator(); return xp.Select("/properties"); }
Iterate through document tabs in XSLT?
Hi All,
I'm working on a doc type which has a lot of tabs with properties underneath. What I would like to do is be able to iterate through the tabs and write out the property name & alias of each property under a tab (With the tab name as a header)
Is this possible in XSLT or would I have to write some custom code using the API? I can see in the database that properties are linked to a tabId but can't find out how to use this data.
This is for produces filtering options for a product listing page - i.e. Tab Name - Ingredients would have ten properties I which to write out to screen.
Thanks for any guidance
Adrian
(I'm using Umbraco v4)
This data is not available in XSLT. If you do want to use it you should create an xsltextension.
It would be easier to just write the headers yourself and then iterate the properties.
If you want to know what information is available check /data/umbraco.config.
Ron
Hi Ron,
I would be happy with the fixed headers but - how would I iterate through only certain properties without knowing what tab they where under?
Adrian
Hi Adrian,
you can't access the tab-info in XSLT, simply because that isn't stored in the cache. Look at the umbraco.config file to see what info is there (that's the file that gets cached and that info you can access with xslt.
Do the tabs change frequently? If not, you might want to place them in the xslt (hardcoded). You define them in the document-type, so you know which tabs you added there. At least, that's the way I should do it, takes the least amount of effort and no need for custom code, which keeps it fast.
If you must access the data, you'd need to create custom code. This means that you have to make DB-calls each time a visitor accesses a page. Take a look at Doc2Form. That creates a dynamic form of a document-type and accesses tab-data as well.
HTH,
PeterD
Hi Adrian,
You could start the property alias with tabName. It's not that nice but it could work.
Ron
Hi guys,
I will look in Doc2Form.
Ron - I did think about starting the alias with the tabName (not nice I agree) but couldnt figure out how to do wildcards in XSLT - i.e. Search for tabName_*
Cheers,
Adrian
Adrian,
I did it with xslt extension code i used was:
using System;
using System.Collections.Generic;
using System.Text;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic;
using System.Xml;
using System.Xml.XPath;
using umbraco.presentation.nodeFactory;
using System.Web;
namespace Umbraco.XSLTExtensions
{
public class Document
{
public static XPathNodeIterator GetPropertiesForDocumentTypeByTab(int DocumentTypeID, string TabAlias)
{
XmlDocument xd = createDocument("properties");
DocumentType dt = new DocumentType(DocumentTypeID);
int i = 1;
foreach (ContentType.TabI t in dt.getVirtualTabs)
{
if (t.Caption == TabAlias) {
foreach (umbraco.cms.businesslogic.propertytype.PropertyType pt in t.PropertyTypes)
{
XmlNode n = createResultNode(xd);
n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "name", pt.Name));
n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "propertyAlias", pt.Alias));
n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "group", pt.Description));
n.Attributes.Append(umbraco.xmlHelper.addAttribute(xd, "id", i.ToString()));
xd.DocumentElement.AppendChild(n);
i++;
}
}
}
XPathNavigator xp = xd.CreateNavigator();
return xp.Select("/properties");
}
private static XmlNode createResultNode( XmlDocument xd)
{
XmlNode x = xd.CreateNode(XmlNodeType.Element, "property", "");
return x;
}
private static XmlDocument createDocument(string rootName)
{
XmlDocument xd = new XmlDocument();
xd.LoadXml("<" + rootName + "/>");
return xd;
}
}
}
take a look at documentation on how to implement xslt extension in umbraco to actually set it up and use in xslt.
Regards
Ismail
Ismail,
Thanks for the reply. I will have a look at implementing your solution.
Thanks all for replying
Adrian
is working on a reply...