Boolean field showing where I don't need

Topics: Customizing Orchard, Troubleshooting
Feb 26, 2013 at 5:05 PM
Hi, I'm new using Orchard CMS and I'm with a little problem, described below:

First, I created a new content type and I added a boolean field in it.
Then, this field shows at the Content page of Admin area and also at the List page I created to list all the new content type I created.
But I use this boolean field to check if it use a read more link or a learn more button at the container widgets I created to show on the home page which is the only place I want to show, at the others mustn't appear.

I tried to find a way to identify what is the current page but Orchard seems not have anything like this.
I could use the current URL and code a IF-ELSE condition, but this is not a good solution because the URL of the page can be changed in the future.

Anybody knows something that can help me?

Thanks,
Letícia
Coordinator
Feb 26, 2013 at 5:06 PM
Feb 26, 2013 at 5:13 PM
Edited Feb 26, 2013 at 5:13 PM
BertrandLeRoy wrote:
Please read this: http://docs.orchardproject.net/Documentation/Understanding-placement-info
Thanks BertrandLeRoy for your answer, but I already tried with the placement-info and unfortunately nothing.
Coordinator
Feb 26, 2013 at 5:14 PM
Then you should probably have mentioned it ;) What did you try and how did it fail?
Feb 26, 2013 at 5:50 PM
Edited Feb 26, 2013 at 6:05 PM
Sorry for not mentioned it.
I just tried this, with placement-info and looking for any object from Orchard which could provide me any info I could use, like I said, what is the current page, for example.

Look at what I tried with placement-info...
I put:
<Match Path="/Admin"> <Place Fields_Boolean="Nowhere" /> </Match>
And also:
<Match Path="/Admin"> <Place Fields_Boolean="-" /> </Match>
Then at Admin area on the Content page it is what I see:
Image

The links you see at the image in the red box, I only want to appear at the home page, not at the Admin Content Page and the page with these list.

Note:
I customized the file Boolean.cshtml from \src\Orchard.Web\Modules\Orchard.Fields\Views\Fields and below it is my code:
@*  
ORIGINAL CODE OF ORCHARD CMS

@using Orchard.Utility.Extensions
@{
    string valueToDisplay;
    bool? booleanValue = Model.ContentField.Value;
    if (booleanValue.HasValue) {
        valueToDisplay = booleanValue.Value
            ? T(Model.Settings.OnLabel).ToString() 
            : T(Model.Settings.OffLabel).ToString();
    }
    else {
        valueToDisplay = T(Model.Settings.NotSetLabel).ToString();
    }
    if (!string.IsNullOrEmpty(valueToDisplay)) {
        string name = Model.ContentField.DisplayName;
    <p class="text-field text-field-@name.HtmlClassify()">
        <span class="name">@name:</span>
        <span class="value">@valueToDisplay</span>
    </p>    
    }
}*@

@* MY CUSTOM CODE *@
@{ 
    Orchard.ContentManagement.ContentItem contentItem = Model.ContentPart.ContentItem;

    if(contentItem.ContentType.Equals("Article")){
        string fieldName = Model.ContentField.Name;
        var fieldValue = Model.ContentField.Value;

        bool moreLink = true;

        if (HasText(fieldName) && HasText(fieldValue))
        {
            if (fieldName == "LearnMoreButton")
            {
                moreLink = (bool)fieldValue;
            }
        }


        if(moreLink)
        {
            <span class="learn-more-link">
                @Html.ItemDisplayLink(T("Learn more").ToString(), contentItem)
            </span>
        }
        else
        {
            <span class="read-more-link">
                @Html.ItemDisplayLink(T("[ read more ]").ToString(), contentItem)
            </span>
        }
    }
}
Sorry if I can't explain better, English isn't my language.

Thanks,
Leticia
Coordinator
Feb 26, 2013 at 6:05 PM
Edited Feb 26, 2013 at 6:08 PM
I'm afraid you'll have to modify the placement in TheAdmin theme. Not the cleanest thing, but it will work. Also, you should match on display type, not path. SummaryAdmin is the display type to match on.
Feb 26, 2013 at 6:19 PM
BertrandLeRoy wrote:
I'm afraid you'll have to modify the placement in TheAdmin theme. Not the cleanest thing, but it will work. Also, you should match on display type, not path. SummaryAdmin is the display type to match on.
Ok, thanks.
It works for the Admin Content Page, but and how about the List Page?

Here is the image of these page:

Image

Letícia
Coordinator
Feb 26, 2013 at 6:41 PM
That is the Summary display type. This one you set in your theme, not in the admin theme, but it's pretty much the same solution.
Feb 26, 2013 at 7:07 PM
BertrandLeRoy wrote:
That is the Summary display type. This one you set in your theme, not in the admin theme, but it's pretty much the same solution.
But, I need to show this at the home page (in the container widget I created) and the page of the image is a List page of my content type Article, if I put in the placement-info, the links will not appear at the home page.
Coordinator
Feb 26, 2013 at 11:40 PM
I don't understand. Do you want it to show or to be hidden?