Transformation in a Custom Table

Sarah Bartell asked on April 22, 2016 19:33

Long story short, here's what I'm trying to do.

I set up a custom table that will house downloadable collateral links. I want to use 1 repeater web part on our product page templates to then list the top 2 most relevant pieces of content for that product.

So then, I need to match up the collateral with the product page, I thought I could do this in the custom table by creating a list box field (titled SolutionID) and the choices would be NodeID;Product Name, so when we enter new content, we can assign it's related product. Then in the transformation, I want to use an if statement to say "if current document node id = this new SolutionID field, then display the document title (and url)."

I cannot get this to work for the life of me. I'm using a text/xml transformation. My code looks like this:

{% if(DocumentContext.CurrentDocument.NodeID == GlobalObjects.CustomTables["customtable.contenttest"].Items.ItemsAsFields.SolutionID) {return <a href="{%DocumentURL%}"> {%DocumentName#%}</a> } #%}

What am I missing?

Recent Answers


Trevor Fayas answered on April 22, 2016 19:45 (last edited on December 10, 2019 02:30)

In the transformation, the row should be the normal {% %} context, so you should do the following.

For the DocumentURL and Name, you may need to use DocumentContext.DocumentURL and DocumentContext.DocumentName though if those values are not from the custom table.

{% if(DocumentContext.CurrentDocument.NodeID == SolutionID) { return "<a href=\"|+DocumentURL+"\">"+DocumentName+"</a>"; } |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Sarah Bartell answered on April 22, 2016 20:15

Thanks Trevor! I tried that code but nothing is rendering on the page. And my test page node ID definitely matches one of the custom table solution IDs. The DocumentURL and DocumentName fields are part of the custom table. What else could I be missing?

Does it make sense to try to match up the documents using NodeID & my solutionID field in the custom table? I can't think of another way to accomplish this.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on April 23, 2016 06:36 (last edited on December 10, 2019 02:30)

Try this one:

{% 
foreach (citem IN GlobalObjects.CustomTables["customtable.contenttest"].Items.Where("SolutionID="+Documents[NodeAliasPath].NodeID)) {
"<a href='"+citem.DocumentURL+"'>"+citem.DocumentName+"</a><br />";
}
|(identity)GlobalAdministrator%}
1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.