Get current document property value

Vic Alfred Inting asked on December 4, 2014 14:59

I currently have a document type that extends the base article type with a few additional properties. I've created a repeater web part within the detail page that shows similar articles based on the ArticleCategory value.

I've tried to put this in the WHERE clause of the web part: ArticleCategory = '{%CurrendDocument.GetValue("ArticleCategory")%}'

And it doesn't work. {%CurrendDocument.GetValue("ArticleCategory")%} doesn't resolve or display anything. What's the correct macro to access a custom field/property of the current document?

Thanks!

Correct Answer

Brenden Kehren answered on December 4, 2014 15:11

Looks like your syntax is just a little off, you're looking for CurrendDocument vs. CurrentDocument. When all else fails, typically the event log has something in it but not always.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Bui Tuong answered on December 5, 2014 03:58 (last edited on December 10, 2019 02:30)

Hi, you can try this : ArticleCategory = '{%CurrendDocument["ArticleCategory"]|(identity)GlobalAdministrator%}'

Cheers

0 votesVote for this answer Mark as a Correct answer

Vic Alfred Inting answered on December 5, 2014 04:20 (last edited on December 10, 2019 02:30)

Wow, just missed that typo. Appreciate it Brenden.

On a similar note, I'm trying to filter out the current article from the repeater and have tried to update my WHERE clause but have failed:

ArticleCategory = '{%CurrentDocument.GetValue("ArticleCategory")|(identity)GlobalAdministrator%}

Not sure if it doesn't like the && or the !=, could you help me out please?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 5, 2014 06:24 (last edited on December 10, 2019 02:30)

For security purposes Kentico protects from SQL Injection UNLESS you tell it otherwise. Check this out. By moving your whole where clause into a macro like so

{%ArticleCategory = '" + CurrentDocument.GetValue("ArticleCategory") + "' && ID != " + CurrentDocument.IDCurrentDocument|(handlesqlinjection)false|(identity)GlobalAdministrator%}

should resolve your problem.

1 votesVote for this answer Mark as a Correct answer

Vic Alfred Inting answered on December 5, 2014 08:03 (last edited on December 10, 2019 02:30)

^^Appreciate the replies Brenden. Is this specific for Kentico 8? I'm currently using Kentico 7 and the above doesn't work. Even moving my prior clause into a macro doesn't work.

Works: ArticleCategory = '{%CurrentDocument.GetValue("ArticleCategory")|(identity)GlobalAdministrator%} (even adding |(handlesqlinjection)false doesn't work)

How do we normally represent conditionals like AND and != in the properties when not using macros?

2 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on December 5, 2014 13:33 (last edited on December 10, 2019 02:30)

When using |(handlesqlinjection)false it needs to be on the macro(s) being rendered as a whole, which is why I suggested creating one single macro. Looks like I had my syntax wrong, there needs to be an opening double quote like so: (you're building a string to pass to the where clause so it has to be correct K# syntax)

{%"ArticleCategory = '" + CurrentDocument.GetValue("ArticleCategory") + "' && ID != " + CurrentDocument.IDCurrentDocument|(handlesqlinjection)false|(identity)GlobalAdministrator%}

Also note the event log might help to troubleshoot why your macro isn't working, if not, you can turn on debugging for macros and see exactly what is being rendered.

2 votesVote for this answer Mark as a Correct answer

Vic Alfred Inting answered on December 9, 2014 09:47 (last edited on December 10, 2019 02:30)

^^Still had issues with that. Anyhow I got it fixed, here were some findings:

  1. My document type had a different field for ID, it's actually called PetArticlesID
  2. The && portion doesn't work, I tried AND, then it worked

This was my final where clause for anyone who needs it:

PetArticlesID != '{%CurrentDocument.GetValue("PetArticlesID")|(identity)GlobalAdministrator%}'

0 votesVote for this answer Mark as a Correct answer

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