Hinterlasse einen Kommentar

How to use the new Relationship Management in 2SexyContent

With 2SexyContent 5.3, we introduced the relationship feature. This means that some sets of information can be related to each other. For example, a blog entry that has a specific author or multiple categories.

We’ve also created a video about relationship management, watch it here.

Preparing the Content Types

First, create the Content Types you want to connect. These types could look like this, if you have a blog entry and author:

Blog Entry

  • Title (String)
  • Description (String with WYSIWYG option)

Author

  • Name (String)
  • Description (String with multiline-option)
  • Image (File)

To enable users to choose an author for each blog entry, create a field named Author with the new field-type Entity.

EAVManagement-Author1

Then configure the EntityType field for the author, set it to Author (the name of the Content Type for authors).

EAVManagement-Author2

After that, you should be able to choose an author for every entry you edit:

EAVManagement-Author3

It’s also possible to enable the selection of multiple entities. Check the AllowMultiValue (configuration of the entity field).

Using in a template

Now that you can enter the data with relationships, you might want to output this in a Razor templates (Token templates do currently not support relationships).

If you have the same content type structure as in the example above, you can paste this into your template:

<br /><br />&lt;h1&gt;@Content.Title&lt;/h1&gt;<br />&lt;p&gt;@Html.Raw(Content.Description)&lt;/p&gt;<br /><br />@* If an author is selected, show it *@<br />@if(Content.Author.GetType() != typeof(String) &amp;&amp; Content.Author.Count &gt; 0) {<br />    var Author = Content.Author[0];<br />    &lt;h2&gt;About the author @Author.Name&lt;/h2&gt;<br />    &lt;img src="@Author.Image?h=100&amp;w=100" alt="@Author.Name" /&gt;<br />    &lt;br /&gt; <br />    @Author.Description<br />}<br /><br />

This will show the author, if it has been selected. Line 5 makes sure the template still works if no author has been selected. Line 6 defines the variable Author as the first Author in Content (note: The field Author could also contain multiple authors).

To list all assigned authors (or any other list of assigned entities), wrap the author HTML into a foreach loop:

<br /><br />@* Show all authors *@<br />@if(Content.Author.GetType() != typeof(String) &amp;&amp; Content.Author.Count &gt; 0) {<br />    foreach(var Author in Content.Author)<br />    {<br />        &lt;div&gt;<br />            &lt;h2&gt;About the author @Author.Name&lt;/h2&gt;<br />            &lt;img src="@Author.Image?h=100&amp;w=100" alt="@Author.Name" /&gt;<br />            &lt;br /&gt; <br />            @Author.Description<br />        &lt;/div&gt;<br />    }<br />}<br /><br />

Have fun trying out the new relationship features, we hope you like it! If you have any questions, feel free to contact us at info@2sexycontent.org or visit 2sexycontent.org

Raphael

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s

%d Bloggern gefällt das: