Note that there are some explanatory texts on larger screens.

plurals
  1. POOrchard Tokens ->
    primarykey
    data
    text
    <p>Im getting a headache from the Orchard Token Providers and any help would be a blessing. Ive mostly been copying the Comments Tokens. </p> <p>The target is for an email to be sent when a 'Question' content item is published. </p> <p>Here is my solution for the Content Type 'Question':</p> <pre><code>public interface ITokenProvider : IEventHandler { void Describe(dynamic context); void Evaluate(dynamic context); } public class QuestionTokens : ITokenProvider { public QuestionTokens() { T = NullLocalizer.Instance; } public Localizer T { get; set; } public void Describe(dynamic context) { //presume this is correct context.For("Content", T("Content Items"), T("Content Items")) .Token("QuestionText", T("Question Text"), T("Text of the question")) .Token("QuestionAuthor", T("Question Author"), T("Author of the question")); //presume this is incorrect? correct for the content type? context.For("Question", T("Questions"), T("Questions from users")) .Token("QuestionText", T("Question Text"), T("Text of the question")) .Token("QuestionAuthor", T("Question Author"), T("Author of the question")); } public void Evaluate(dynamic context) { Func&lt;IContent, object&gt; questionTextAccessorFromContent = (content) =&gt; { var part = content.As&lt;QuestionPart&gt;(); return part.QuestionText; }; Func&lt;QuestionPart, object&gt; questionTextAccessor = (part) =&gt; { return part.QuestionText; }; Func&lt;IContent, object&gt; authorAccessorFromContent = (content) =&gt; { var part = content.As&lt;QuestionPart&gt;(); return part.Author; }; Func&lt;QuestionPart, object&gt; authorAccessor = (part) =&gt; { return part.Author; }; //doesnt work context.For&lt;IContent&gt;("Content") .Token("QuestionText", (Func&lt;IContent, object&gt;) (content =&gt; content.As&lt;QuestionPart&gt;().Record.QuestionText)) .Token("QuestionAuthor", (Func&lt;IContent, object&gt;) (content =&gt; content.As&lt;QuestionPart&gt;().Record.Author)); //doesnt work context.For&lt;IContent&gt;("Question") .Token("QuestionText", (Func&lt;IContent, object&gt;) (content =&gt; content.As&lt;QuestionPart&gt;().Record.QuestionText)) .Token("QuestionAuthor", (Func&lt;IContent, object&gt;) (content =&gt; content.As&lt;QuestionPart&gt;().Record.Author)); //doesnt work context.For&lt;QuestionPart&gt;("Question") .Token("QuestionText", (Func&lt;QuestionPart, object&gt;) (content =&gt; content.Record.QuestionText)) .Token("Author", (Func&lt;QuestionPart, object&gt;) (content =&gt; content.Record.Author)); ; } private static string QuestionText(IContent question) { var questionPart = question.As&lt;QuestionPart&gt;(); return questionPart.QuestionText; } private static string Author(IContent question) { var questionPart = question.As&lt;QuestionPart&gt;(); return questionPart.Author; } </code></pre> <p>}</p> <p>This is the Action (when the Question is published), it sends a email with the body text: (updated to test Medeiros suggestion)</p> <pre><code>&lt;p&gt;A question has been created by: {Content.QuestionAuthor}&lt;/p&gt; &lt;p&gt;A question has been created by: {Content.QuestionAuthor.Text}&lt;/p&gt; &lt;p&gt;A question has been created by: {Content.QuestionAuthor.Value}&lt;/p&gt; &lt;p&gt;A question has been created by: {Question.QuestionAuthor}&lt;/p&gt; &lt;p&gt;A question has been created by: {Question.QuestionAuthor.Text}&lt;/p&gt; &lt;p&gt;A question has been created by: {Question.QuestionAuthor.Value}&lt;/p&gt; &lt;p&gt;Message: {Content.QuestionText}&lt;/p&gt; &lt;p&gt;Message: {Content.QuestionText.Text}&lt;/p&gt; &lt;p&gt;Message: {Content.QuestionText.Value}&lt;/p&gt; &lt;p&gt;Message: {Question.QuestionText}&lt;/p&gt; &lt;p&gt;Message: {Question.QuestionText.Text}&lt;/p&gt; &lt;p&gt;Message: {Question.QuestionText.Value}&lt;/p&gt; </code></pre> <p>All 'my' tokens are replaced with blank text. Other tokens like: {Content.ContentType} {User.Email} work just fine. Any mistakes or hints that anyone notices will be very useful. </p> <p>Thanks, Matt</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload