Workflows and Tokenizer

Topics: General
Oct 4, 2013 at 10:57 AM
Hello,
I have been following this tutorial on creating a HTML Templater.

Instead of using Rules, i would like to use Workflows to send the template

I would like to use tokenizer to get details from created content, in this case an "order"

The trouble im having is getting tokenizer to actually get the details from the newly created order content type.
All of the Token code in Orchard seem to be for getting the values from Fields, not created content.

Here's what i have attempted so far
OrderTokens.cs
   public class OrderTokens : ITokenProvider {
        private readonly IContentManager _contentManager;
        private readonly IWorkContextAccessor _workContextAccessor;

        public OrderTokens(
            IContentManager contentManager,
            IWorkContextAccessor workContextAccessor) {
            _contentManager = contentManager;
            _workContextAccessor = workContextAccessor;
            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }

        public void Describe(DescribeContext context)
        {
            context.For("OrderHeaderPart", T("Customer Id"), T("Tokens for CustomerId"))
                .Token("CustomerId", T("CustomerId"), T("The Customer Id."))
                       ;
            //context.For("Content", T("Order"), T("Order"))
            //    .Token("CustomerId", T("Customer Id"), T("Numeric key value of the Customer."))
            //    .Token("OrderId", T("Order Id"), T("Numeric key value of the Order."))
            //    ;

        }

        public void Evaluate(EvaluateContext context)
        {
            context.For<IContent>("Content")
                .Token("CustomerId", (Func<IContent, object>)(content => content.As<OrderHeaderPart>().CustomerId))
                ;
            //context.For<IContent>("Content")
            //    .Token("CustomerId", content => content.As<OrderHeaderPart>().CustomerId)
            //    .Chain("CustomerId", "Content", content => _contentManager.Get(content.As<OrderHeaderPart>().CustomerId))
            //    .Token("OrderId", content => content.As<OrderHeaderPart>().OrderId)
            //    .Chain("OrderId", "Content", content => _contentManager.Get(content.As<OrderHeaderPart>().OrderId))
            //    ;
        }
    }
Is there anything i am missing? Or is there a module that uses a similar method that you recommend i take a look at?

Many thanks
Developer
Oct 4, 2013 at 3:18 PM
Your commented-out code looks ok - you correctly extended the Content token.

I guess the thing you're missing is that Content inside a workflow is accessed via Workflow.Content token (not just Content), so in your case getting a CustomerId would look like {Workflow.Content.CustomerId}.
Oct 7, 2013 at 12:12 PM
Thanks for your reply!
You actually helped me find the cause of the error, which was me not changing the token name when i changed the token Description. Silly error, my mistake.

Thanks again