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

Hi, you can try this : ArticleCategory = '{%CurrendDocument["ArticleCategory"]%}'

Cheers

0 votesVote for this answer Mark as a Correct answer

Vic Alfred Inting answered on December 5, 2014 04:20

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")%}' && ID != {%CurrentDocument.IDCurrentDocument%}

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

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%}

should resolve your problem.

1 votesVote for this answer Mark as a Correct answer

Vic Alfred Inting answered on December 5, 2014 08:03

^^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")#%}' Doesn't Work: {%ArticleCategory = '" + CurrentDocument.GetValue("ArticleCategory") + "'#%} (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

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%}

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

^^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")#%}' AND ArticleCategory = '{%CurrentDocument.GetValue("ArticleCategory")#%}'

0 votesVote for this answer Mark as a Correct answer

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