Token Fun With PXM
If you've had any experience with Sitecore Print Experience Manager you'll probably know what powerful features it brings to the world of integration between print and Sitecore.If not you can get a good overview here:
https://community.sitecore.net/technical_blogs/b/getting_started_with_sitecore_print_experience_manager/posts/getting-started-with-pxm
Recently a customer asked for what I would expect to be a reasonable feature, but first a little background.
When you create a PXM project (aside from the master document step) you effectively create objects or elements using InDesign in your document, for example a text frame that can populated by either Sitecore content or user entered content via the Document Publisher. This element is them saved back to Sitecore as a snippet, effectively a Sitecore item in a standard hierarchy.
But what happens if the document you are usng has the same pieces of text in multiple places, i.e. company name. In a standard PXM set up, you would have this field repeated numerous times and be forcing the person creating the document to type the same text in multiple times.
Behold the brilliant customisations available via the SPEAK interface and a simple but powerful solution from a developer working for the customer, and yes it does use tokens and yes there is curly brackets involved (steady!!)
The simple solution was to include curly bracketed tokens in the actual InDesign template itself, i.e. {company name}.
And then using the framework already provided, simply add a button to the edit screen in the Document Publisher that calls a spot of code that parses the template for curly bracket wrapped values and present them in a modal dialogue, enter your values, click update and the values are written back into the document, replacing the original curly barketed ones.
Click Preview again and voila, there's your document with every instance of company name (for example) replaced with your (entered once) value.
This approach gets around some tricky issues with text flow etc. and also doent need anthing tricky and somewhat obscure like InDesign variables.
One another note two quick solutions for hiding Document Publisher fields you dont want the user to see:
For a text snippet for example, create a new template that inherits from the original element and assign it to the snippet, Document Publisher wont pick it up but it will appear in the document preview and final render.
OR just use security permissions on the element itself.
Have yourself a whole heap of PXM fun and thanks for reading.