Accessing Body

Topics: Writing themes
Aug 21, 2012 at 3:56 PM

Hey there,

I've created a custom content type and added an image field. Now I like to edit the detail page and try to get access to the body part so I can place the image above the content.

Thanks in Advance.

Aug 21, 2012 at 7:53 PM

You should be able to use placement to put the image above the body text.  Have you tried editing your Placement.info file?

Aug 22, 2012 at 8:08 AM
Edited Aug 22, 2012 at 8:13 AM

Didn't thought about that before, but I like to remove the headline with the field name above the picture. 

I like to write something like this in my Content.Detail file (just without using the Model.Content):

<article>
        <header>
            @{ 
                var fileName = Model.ContentItem.News.NewsImage.FileName;
                if(!string.IsNullOrEmpty(@fileName)){
                    <img src="@Url.Content(fileName)" alt="@Model.Title" />
                }
            }

            <h2>@Model.ContentItem.TitlePart.Title</h2>
            <h4>@Model.ContentItem.News.Subtitle.Value</h4>
        </header>
            @Display(Model.Content)
</article>
Aug 22, 2012 at 4:14 PM

You could use an alternate to completely override the Content template, but I would just use an alternate for the image field, and use placement to put it before the title, body, etc. 

Aug 23, 2012 at 9:44 AM

Thanks Brandon!

I used @Html.Raw(Model.ContentItem.BodyPart.Text) instead of @Display(Model.Content) in my alternate to solve the problem.