Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>IVe re-written the token provider and it works sort of... (and now works completely) </p> <pre><code>public class QuestionTokens : Orchard.Tokens.ITokenProvider { private readonly IContentManager contentManager; private readonly IWorkContextAccessor workContextAccessor; public QuestionTokens(IContentManager contentManager, IWorkContextAccessor workContextAccessor) { this.workContextAccessor = workContextAccessor; this.contentManager = contentManager; T = NullLocalizer.Instance; } public Localizer T { get; set; } /// &lt;summary&gt; /// Describes the specified context. /// &lt;/summary&gt; /// &lt;param name="context"&gt;The context.&lt;/param&gt; public void Describe(DescribeContext context) { 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")); } /// &lt;summary&gt; /// Evaluates the specified context. /// &lt;/summary&gt; /// &lt;param name="context"&gt;The context.&lt;/param&gt; public void Evaluate(EvaluateContext context) { context.For&lt;IContent&gt;("Content") .Token("QuestionText", content =&gt; QuestionText(content, context)) .Token("QuestionAuthor", content =&gt; Author(content, context)); } private string QuestionText(IContent question, EvaluateContext context) { var questionPart = question.As&lt;QuestionPart&gt;(); return questionPart.QuestionText; } private string Author(IContent question, EvaluateContext context) { var questionPart = question.As&lt;QuestionPart&gt;(); return questionPart.Author; } } </code></pre> <p>I can now debug the code at least in the private QuestionText and Author methods. The value retrieved is 'null' due to the published event firing when this line is fired in the controller: services.ContentManager.Create("Question");</p> <p>so the content item has not been populated and the 'published' event is firing before its life has begun. Time to play about with its content type settings a bit to see if that makes a difference...</p> <p>Finally all working as needed. The Events section 'published' event is still happening when i dont expect it to so I've changed the life of the content. </p> <p>From a controller: (some code into a service removed so I don't have a post more code)</p> <pre><code>var item = services.ContentManager.New&lt;Models.QuestionPart&gt;("Question"); this.TryUpdateModel(item); services.ContentManager.Create(item.ContentItem); //where the event is firing Services.ContentManager.Publish(item.ContentItem); //where i expected the event to fire :) </code></pre> <p>Originally it was create, update and save. But the events restricted that. So now its new, update and create. As for the tokens. They are simply: {Content.QuestionAuthor} and {Content.QuestionText}. Nice and simple when everything is working, and everything is right. </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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