Search code examples
javascriptc#.netcontent-management-systemorchardcms

Orchard CMS Placement by field name


The documentation is so useless when it comes to specialised question. Let's assume I have a contentPart with multiple fields (e.g. Fields_Common_Text). Now assume I have a name field and an email field (these are just examples the actual case might be more complex.

Also assume my part has another string field we call title. So

CustomContentPart:
    Fields_Common_Text name
    Fields_Common_Text email
    this.As<TitlePart>().Title

Now the real question begins here. How do I use placement.info file to place title in between these two. Since I can do the following:

<Place Parts_CustomContent="Content:0" />
<Place Fields_Common_Text="Content:1"/>

But that will place both text fields after the title. How do I place the fields by their name? (Or do it any other way, using alternates does not work since alternates are heirachy of shapes and render zones, therefore these attributes are not accesible from the parent shape (in a clean manner))


Solution

  • I actually managed to solve this issue

    The solution is exactly the way I suspected it would be. Now let's assume my CustomPart's shape also renders the title inside it (so the actual TitlePart is placed elsewhere and rendered in the Header zone) So there are three shapes:

    Parts_CustomContent
    Fields_Common_Text 
    Fields_Common_Text
    

    Now in order to place them in Content in the order of name text field, CustomContentPart and email text field add the following to your placement.info file:

    <Place Fields_Common_Text-name="Content:0"/>
    <Place Parts_CustomContent="Content:1" />
    <Place Fields_Common_Text-email="Content:"/>
    

    NOTE: Remember name and email are official names you have assigned to your TextFields (either through gui or Migration). Of course Capitalised Name and Email are better names I was just trying to stay consistent with the question body.

    Only a specific ContentType

    I tried using content type signature as well as field name but it didn't work. If you would like to only apply that placement to certain content types you must use:

    <Math ContentType='YourDesiredContentType'>
        <!-- Your Place tags -->
    </Match>