Macro to retrieve document property on print template

emma zelewsky asked on March 19, 2015 20:16

Hi folks,

Hope someone can help me with a macro for a print-friendly template. The template is a generic page that uses a query string to load the right document. The macro will trigger the visibility of a webpart based on the value of a column in the underlying document type. The URL for the print template is structured like so -- mysite.com/pages/print.aspx?printpath=/path/to/doc/ArticleName&classname=namespace.documenttype

And a repeater on the template uses the query string for the content path.

The {%CurrentDocumuent.DoSomething%} macro obviously won't work in this context because I want to get a column from the document ArticleName, which has a link to the printer-friendly view and is the referring page.

Can a macro be used to get a value (column in the doctype) from the document ArticleName? Or is the only way to return values via a repeater that has the content path set to {?printpath?} and an Eval("myColumn")

Thanks!

Correct Answer

Brenden Kehren answered on March 24, 2015 13:24

Two repeaters would be fine. You wouldn't need an "if-compare" though. Are you making the subscribers log in? Or are they assigned a security role? If so, in the visibility section set the "Display to roles:" property to show only for notauthenticated on the public repeater and authenticated PLUS the security role(s) who have access to the secure documents. This way it keeps things clear and easy.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on March 20, 2015 12:25

What I understand is you have a single page with a single repeater on it which displays content (in print friendly format) for multiple page/doc types. What you want is a way to dynamically pick the column names based on the URL parameter correct?

If so, what I'd do is in all the page/doc types you expect this to happen with create a transformation with the same name, maybe PrintFriendly. Then in your repeater you'll be setting your WHERE clause based on the query string for the class name, correct? What you can do now is set the transformation name as a macro like {%ClassName%}.PrintFriendly. So now any document being rendered will automatically change to use the newly created PrintFriendly transformation, i.e.: CMS.Article.PrintFriendly or CMS.Event.PrintFriendly, etc.

Hope this helps!

0 votesVote for this answer Mark as a Correct answer

emma zelewsky answered on March 23, 2015 23:39

Thanks Brenden! The {%ClassName%}.PrintFriendly is great for handling multiple doctypes with one template, but I'm after something else.

The template is for a single doctype, and the current repeater and transformation work OK for those documents. What I was attempting to do was toggle visibility of a zone based on a field in the document. The field indicates if the article is public or for subscribers only.

Instead of a macro, it looks like the easier way will be a separate repeater with an if-compare that calls one transformation for public documents and another for subscriber-only documents.

0 votesVote for this answer Mark as a Correct answer

emma zelewsky answered on March 24, 2015 19:50

Thanks, Brenden! That's an elegant approach!

0 votesVote for this answer Mark as a Correct answer

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