Note that there are some explanatory texts on larger screens.

plurals
  1. POImplementing List.cshtml for Projection throws 'Orchard.ContentManagement.ContentItem' does not contain a definition for 'TagsPart'
    primarykey
    data
    text
    <p>I have implemented List.cshtml to provide a custom display for an image gallery. This is the first time I have tried to override a Projection with a Template and at first it seemed to work fine. Then I noticed that when I try to access the Projection on the backend Orchard 1.7 falls over with:</p> <blockquote> <p>RuntimeBinderException 'Orchard.ContentManagement.ContentItem' does not contain a definition for 'TagsPart'</p> </blockquote> <p>Here is some code from the template List.cshtml:</p> <pre><code>List&lt;TagRecord&gt; uniqueTags = new List&lt;TagRecord&gt;(); List&lt;dynamic&gt; items = Model.Items; if (items != null &amp;&amp; items.Any()) { foreach (var item in items) { if (item != null &amp;&amp; item.ContentItem != null) { TagsPart part = item.ContentItem.TagsPart; if (part != null &amp;&amp; part.CurrentTags != null) { foreach (var t in part.CurrentTags) { if (!uniqueTags.Contains(t)) { uniqueTags.Add(t); } } } } } </code></pre> <p>I am ignorant on a couple of points, which I suspect may be causing the error:</p> <ol> <li><p>How to specify a template for a Projection (more specific than 'List.cshtml'). Can I use Placement.info? How?</p></li> <li><p>How should I test for the presence of a specific part in the ContentItem? Just assigning <code>TagsPart part = item.ContentItem.TagsPart;</code> throws the exception above.</p></li> </ol> <p><strong>UPDATE:</strong> I had implemented this as a Module; that is, the List.cshtml was in the Views folder of a simple Module. If I move List.cshtml to the Theme then the problem goes away. However, I would still prefer to use a module so that the layout is independent of the theme.</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