How to get the summery-image URL in Orchard view override - orchardcms

I use Orchard CMS 1.10.1. I'm overriding View of a summary display type of a content type, for this, I need url of image field in display type summary.
I can get the image url itseft this way :
#Model.ContentItem.Product.Images.FirstMediaUrl
This is part of the view altenate:
<div class="col-sm-4">
<img src=#Model.ContentItem.Product.Images.FirstMediaUrl />
</div>
My question is how can I get url of summary of this image? So I can replace the above url with the summary one.

You can do it like this:
#{
var image = Model.ContentItem.Product.Images.MediaParts.First();
}
<div class="col-sm-4">
#Display(BuildDisplay(image, "Summary"))
</div>
You need to display it like this because Image in Orchard is a content item, but if you want to display image url inline with resizing you can do the following:
#{
var imageUrl = Model.ContentItem.Product.Images.FirstMediaUrl;
}
<div class="col-sm-4">
<img src="#Display.ResizeMediaUrl(Width: 200, Height: 200, Mode: "crop", Alignment: "middlecenter", Path: imageUrl)" />
</div>

Instead of hardcoding using the URL, use the Placement.info to obtain the summary shape of the media item.
In your view override:
<div class="col-sm-4">
#Display(Model.ImageSummary)
</div>
And in your Placement.info
<Match ContentType="MyContentType">
<!-- ImageSummary is the local zone name which you then can display with
#Display(Model.ImageSummary) in Content-MyContentType.cshtml -->
<Place Fields_MediaLibraryPicker_Summary="ImageSummary:1" />
</Match>

Related

OrchardCMS Getting the Attached Layout Part from the CustomType object in a Shape Alias

I am trying to build a component for my Orchard Website.
I am using a Custom ContentType and shape tracing.
Its going exactly as I expect, but one of the parts is the LayoutPart.
All the other fields I am using to generate the HTML structure of the component.
In the center of it, I was going to display whatever the user puts into a LayoutPart inside of the middle of it.
EDIT
Was missing the Placement.info text.
/EDIT
The ContentType has the following fields (which I am using to build the html):
ID (Text)
NextItem (NextItem)
ModuleType (Text)
BackGroundImage MediaImage
and the following ContentParts
CommonPart
NavigationPart
LayoutPart
What I need is the LayoutPart from the Model object, so I can place its content in a div the cshtml with
BuildDisplay(layoutPart, "DisplayType")
I have tried looking through the docs, and googling it.
I suspect that since I am new to both Orchard and Razor I don't have the right vocabulary yet.
Fixed Thank you!
Here's my final code:
#using Orchard.Utility.Extensions;
#using Orchard.ContentManagement;
#using Orchard.Layouts.Models;
#using Orchard.DisplayManagement.Shapes
#using Orchard.Layouts.Helpers;
#{
var tag = Tag(Model, "div");
var id = Model.Content.Items[0].Value;
var css = Model.Content.Items[1].ContentField.Value;
var nextID = Model.Content.Items[2].ContentField.Value;
var backgroundPath = Model.Content.Items[3].ContentField.FirstMediaUrl;
var customstyle = "";
if (css == "module-hero")
{
css = "module-hero fullheight parallax";
customstyle = "background-image: url(" + backgroundPath + "); background-size: cover; background-attachment: fixed; background-position: center center; background-repeat: no-repeat; ";
}
else if (css == "module-sidekick")
{
customstyle = "background-image: url(" + backgroundPath + "); background-size: cover; background-position: relative; background-repeat: no-repeat; overflow: hidden;";
}
}
#tag.StartElement
<div id="#id" style="#customstyle" class="#css">
<div class="container">
<div class="row">
<div class="col-sm-12 m-t-250">
#Display(Model.ParallaxContent)
<div class="btn-list">
<i style="font-size: 60px" class="fa fa-angle-down"></i>
</div>
</div>
</div>
</div>
</div>
#tag.EndElement
<!-- XML -- >
Placement.info
<Match ContentType="ParallaxModule" DisplayType="Detail">
<Place Parts_Layout="ParallaxContent" />
</Match>
What you're looking for is Shape Relocation. There is an introduction to it here in Sebastien's Harvest 2015 Shapes Talk.
The idea is as follows:
You want to move a part around on the page but you don't want to take full control over the rendering of it, you just want to move the existing bit to somewhere else on the page.
Shape Relocation
First you make up a new zone in your view, name it what you like. In your case it would look something like this:
<div id="#id" style="background: url(#backgroundPath)" class="#css">
<div class="container">
<div class="row">
<div class="col-sm-12 m-t-250">
#Display(Model.MyNewCustomLayoutZone)
<div class="btn-list">
<i style="font-size: 60px" class="fa fa-angle-down"></i>
</div>
</div>
</div>
</div>
</div>
So now you have a new zone which you can target with placements.info called MyNewCustomLayoutZone.
Open up the placements.info file in your theme or module and add this into it:
<Match ContentType="MyCustomContentType">
<Match DisplayType="Detail">
<Place Parts_Layout="MyNewCustomLayoutZone" />
</Match>
</Match>
Where MyCustomContentType is whatever you have called this new content type and MyNewCustomLayoutZone is whatever you called your new zone in the first step.
How do you find out the Parts_Layout bit?
Open up the shape tracing tool and go to the Part / Field you want to move around.
In the first tab, Shape you will see an entry Shape which tells you this.
You can actually use the same technique to move around your fields.
You don't need to make a new zone every time, you can use the existing ones such as:
<Place Parts_Layout="Footer" />
If you wanted to show that bit at the end of this shape.
You can also move it around into shapes that are part of the wider page. These are called global zones. For example if I had created a field of type Text and it was called FooterText I could display it right at the bottom of the site with:
<Place Fields_Common_Text-FooterText="/Footer:after"/>
More info about your options with moving stuff around is in the Understanding the placement.info file over on the official docs.
Hiding custom fields
If you're seeing your custom fields in your main #Display(Model.Content) that you don't want to be displayed to the end-user you can simply hide them with placement.info using a - as the target zone.
This would translate into something like this:
<Match ContentType="MyCustomContentType">
<Match DisplayType="Detail">
<Place Fields_Common_Text-ID="-" />
<Place Fields_NextItem-NextItem="-" />
<Place Fields_Common_Text-ModuleType="-" />
<Place Fields_MediaLibraryPicker-BackGroundImage="-" />
</Match>
</Match>

Pagination widget does not work

This is what I get when using the fluid pagination widget.
it try to jump to the 2nd page but without any success
it generates this URL which look like this
http://example.com/news-stories/essen/?tx__%5B%40widget_0%5D%5BcurrentPage%5D=2
This URL above won't work. It is generated by the Tag
I am using the Menu Type "Thumbnail" of Bootstrap Package. And this is the fluid tag which i use to generate it:
<f:widget.paginate objects="{menu}" as="paginatedItems" configuration="{itemsPerPage: 6, insertAbove: 1, insertBelow: 1}">
<f:for each="{paginatedItems}" as="page">
<div class="col-xs-6 col-sm-6">
<f:link.page pageUid="{page.data.uid}" title="{page.data.title}" class="thumbnail" data="{equalheight: 'item', toggle: 'tooltip'}">
<div class="thumbnail-image">
<f:if condition="{page.files.0}">
<f:if condition="{page.files.0.type} == 2">
<f:media file="{page.files.0}" width="{settings.media.width}" height="{settings.media.height}" />
</f:if>
</f:if>
</div>
<div class="thumbnail-caption">
<f:if condition="{page.data.title}">
<h3><f:format.crop maxCharacters="{settings.title.crop}">{page.data.title}</f:format.crop></h3>
</f:if>
<f:if condition="{page.data.abstract}">
<p><f:format.crop maxCharacters="{settings.abstract.crop}">{page.data.abstract}</f:format.crop></p>
</f:if>
</div>
</f:link.page>
</div>
</f:for>
</f:widget.paginate>
Can anybody help to make the pagination work, should I configure something?
The paginate widget needs a plugin context to work. Even the backend paginate widget needs a controller to function. It would be a nice feature to have paginate widget work with menus and other arrays.

Align photos and captions in a grid

I'm trying to align four pictures with their captions in a square grid.
I'm using the following HTML code:
<div class="grid">
<div class="post-block">
<img src="img1.jpg" />
<div class="caption">caption1</div>
</div>
<div class="post-block">
<img src="img2.jpg" />
<div class="caption">caption2</div>
</div>
<div class="post-block">
<img src="img3.jpg" />
<div class="caption">caption3</div>
</div>
<div class="post-block">
<img src="img4.jpg" />
<div class="caption">caption4</div>
</div>
</div>
and the following CSS code:
.post-block {
display: inline-block;
position: relative;
text-align: center;
}
If images and captions are the same size everything is ok, but when they are different I get this (an example):
I've tried to align images and captions of different sizes using CSS with no success. I need something like this:
Any help would be appreciated.
Thanks in advance
You'll need to use separate block elements at the same DOM level for the image and the caption to achieve what you've shown in the "RIGHT" image. Right now your caption DIV is nested inside the image DIV, and that's gonna do what you've shown. The caption DIV needs to be outside the image DIV.
You will probably want two separate div wrappers around each 2 photos..
Then align images vertically to bottom.
Vertical align images to bottom
<div class="myWrapClass">
<img src="my image">
<img src="my image">
</div>
<div class="myWrapClass">
<img src="my image">
<img src="my image">
</div>
then set the styling via inline or your css file
<div style="vertical-align:bottom;">
or
.myWrapClass{
vertical-align:bottom;
}
check out this site... Use the css properties there to keep it responsive
Example

How to display the publication date of a custom content item in its template

I need to display a publication date in an alternate template. I tried displaying the Model.Meta but it contains nothing.
I tried Model.Parts.Common.PublicationDate to no avail. So how can I access the publication date?
<li>
<a href="#displayUrl">
<div style="padding: 20px 20px 0 20px;">
#Display(Model.Meta) <!--contain nothing-->
#Model.Parts.Common.PublicationDate; <!-- contain nothing -->
<h2>#title</h2>
#shortenedDescription
</div>
<div class="texthover">
<div class="texthover-content">
#if(Model.ContentItem.News.Image.Url != null){
<img src="#Href(Model.ContentItem.News.Image.Url)" />
}
</div>
</div>
</a>
</li>
In the placement file in your theme, add the line:
<Match ContentType="MyType">
<Place Parts_Common_Metadata="Meta:1" />
</Match>

Content as NextPage pagination link in Tumblr

I'm creating a single post per page tumblr template with the body content as the link to the next page - you can see a quick test working here:
There are 4 entries but the 4th doesn't render, probably because there is no 'NextPage'. Any idea how I might get around that to render the last page? or if it is has to be blank how to render a bit of static text.
{block:Text}
<div class="content">
{block:Pagination}
{block:NextPage}
{Body}
{/block:NextPage}
{/block:Pagination}
</div>
{/block:Text}
How about
{block:Text}
<div class="content">
{block:Pagination}
{block:NextPage}
<a href="{NextPage}">
{/block:NextPage}
{/block:Pagination}
{Body}
{block:Pagination}
{block:NextPage}
</a>
{/block:NextPage}
{/block:Pagination}
</div>
{/block:Text}
This way the {Body} should always render, and the link only if there is a next page!

Resources