This project is read-only.

Getting permalink while enumerating items

Topics: Customizing Orchard
Mar 7, 2013 at 3:53 PM
Hi all,

I have created a custom content type and attached the Containable part to it.
I have then created a list of my custom content type and assigned the permalink "/allitems" to it.

I would like that when adding instances of my custom content type to the list the post will automatically generate a permalink like "/allitems/{Content.Slug}". I have tried creating a new pattern in Autoroute section of the content type and making the default one with "{Content.Container}/{Content.Slug}". But this does not work.
Is there any way to generate a pattern like that?

Second question: I have customized the default view that show the list of my content type posts but unfortunately I have not been able to retrieve the permalink to the item. This is my code:
    IEnumerable<object> items = Model.ContentItems;
<div id="gicontainer" class="photos">
@foreach (dynamic item in items) {
    <div class="photo" style="width: 160px; float: left; margin: 10px;">
        <a href="@item"><img src="@Url.Content(item.MyContentType.Cover.Url)" alt="@item.MyContentType.Summary.Value" /></a>
What should I use for the href attribute?
Mar 7, 2013 at 6:15 PM
  1. how does it not work? Look at the default pattern for blog posts.
  2. Url.ItemDisplayUrl
Mar 7, 2013 at 6:20 PM
BertrandLeRoy wrote:
  1. how does it not work? Look at the default pattern for blog posts.
I have corrected in {Content.Container.Slug}/{Content.Slug} and now it is working.

BertrandLeRoy wrote:
  1. Url.ItemDisplayUrl
Where do I can find the property Url? If I do @item.Url.ItemDisplayUrl I get an error...
Mar 7, 2013 at 9:00 PM
@using Orchard.Mvc.Html on top of your file should do the trick.
Mar 8, 2013 at 11:46 AM
Thanks a lot for helping.