I would like to display certain first level menuitem in bold.
This setting should be done by a checkbox when the user create / edit a menu item. (I have a workaround using the Model.Href, but it is not nice).
So I created a boolean field in Content definition / Menuitem URL (I don't know the name of the corresponding content definition in English Orchard).
How to access a custom field (Content Field) from a view?
(There already is a view which is used to customize the menu)
The examples I found use custom shapes, where the fields are accessed as built in fields (e.g. Model.ContentItem.FieldName ). But this is a different case.
With the help of "Piedone", the solution:
Model.Content.ContentItem.MenuItem.FieldTechnicalName.Value
Explanation
Examining the Model object in Visual Studio, the Model is a dynamic shape that have eg. Href property and a Content.
Content is a MenuPart, that is a content part that have a ContentItem property with the content item itself. Technically only content parts have Fields. When you (seemingly) add a field to a type it will be a part corresponding the type's name, that is MenuItem in this case (It's confusing that the display name of 'MenuItem' content type is Custom Link...)
The field's technical name is as you name it. When you add to a type, the Value will be a property of the BooleanField class. (By the way, it is nullable, so if you dont't save after adding the field, it will be null else the value you set).
Related
I am creating a page template. Each page using the template will have a single unique value that gets embedded into the page HTML. The rest of the HTML is constant for all pages. Assume the following is the desired result:
click me
I want a template that provides click me, while allowing the individual pages (content admins) to provide id.
I've tried using an Editable Text web part, and putting the "before" and "after" HTML in the HTML Envelope before and after sections, and adding the ID on the "Page" tab. However, that is not quite working. What is the best way to accomplish this?
This can be done. What you'd want to do is add that field to the page type fields you're adding those pages with. For instance, say you have a list of locations under /locations.
i.e.:
/location/chicago
/location/new-york
/location/minneapolis
The locations themselves (Chicago, New York, Minneapolis) are your custom page type and have a unique field called LocationID. On your template, add a static text webpart (not static HTML because the WYSIWYG editor overwrites the markup you add) and simply add this:
click me
If the LocationID field has a exists AND has a value, it will output it, otherwise it will just leave the URL http://www.example.com/
If you didn't want to show that link at all on other pages, then set the Show for page types property based on the page type you want it to show for in the Visibility section of the static text webpart.
I'm reading through the documentation (https://docs.kentico.com/k9/managing-website-content/configuring-the-environment-for-content-editors/configuring-tags/allowing-users-to-tag-pages-on-the-form-tab) and thought all was good, but when i go to create a new page based on the pate type, my Tag field is greyd out.
At the bottom of documentation page, is states:
If you need to create a custom page type with a tag selector, the tag selector must be bound to a system field
I don't know what this means? I've created a tag group (Global), but I'm stuck.
If your parent page type has the Tag field in it already, the child page type will not allow you to change it, you have to go back to the parent page type to change any attributes about it.
Binding that tag selector to a system field means when you create that field, you need to select system field when you create it vs. a standard field.
I have added a field (media picker field) for "BackgroundPhoto" to the Page content type.
I'm trying to get the page so when that field exists, or has a value, that it's added through css as the background URL to the layout-wrapper found in layout.cshtml.
I have searched and come close to finding how this works, but never accessing a value from a content type on the layout page. Does anyone have an example where this works? Specifically, a value in a page field is added to the "layout-wrapper" item in layout.cshtml.
Thanks for your help!
Technically, the layout wrapper is document.cshtml. You could override that to render a value that you stored in HttpContext from your deeper field template.
To recap: create a template override for your field in your theme; from there, set the value of the field into a HttpContext item; From document.cshtml, retrieve and render that value.
I have created a custom field type as it is there in sharepoint OOTB, the difference is only that the end user does not need to check the name i.e I have replaced it with DropDownList. The dropdownlist suggest the no. of users available in the web site for that I have created a FieldClass which inherits from SPFieldUser and a FieldControlClass which inherits from UserField. It is working fine in all conditions i.e when I create a List or Document Libarary it shows me the DropDownList
with respective users after saying OK it creates an item for me. I have overriden a Value property in FieldControlClass as follows,
public override object Value
{
get
{
SPUserCollection userscollection = rootWeb.SiteUsers;
//ddlInfoBox is a DropDownList to which I have Binded the collection of users in the form of string
SPUser user = userscollection.Web.EnsureUser(this.ddlInfoBox.SelectedValue);
SPFieldUserValue userval = new SPFieldUserValue(user.ParentWeb, user.ID, user.LoginName);
return userval;
}
set
{
SPFieldUserValue userval = (SPFieldUserValue) this.ItemFieldValue;
this.ddlInfoBox.SelectedValue = userval.Lookupvalue; //Here look up value is nothing but a Login name e.g In-Wai-Svr2\tjagtap
}
}
Due to above property the Custom Field's Value for this current ListItem will be stored as SPFieldUserValue e.g 27#;In-Wai-Svr2\tjagtap.
The main problem is here, when this particular ListItem is shown in the list page views e.g on AllItems.aspx or the custom view pages associated with it, it shows the
number as 27 as a FieldValue insted of HyperLink with text as "In-Wai-Svr2\tjagtap" and PostBackURL as "/_layouts/userdisp.aspx?ID=27".
When I edit this Item it makes the respective value selected in the dropdownlist, also while viewing this item i.e on DispForm.aspx it also shows the hyperlink. I have
acheived it by writting a custom logic in createchildcontrol() method i.e by using ControlMode if it is New or Edit then fill the dropdown list, if it is Display then get the ItemFieldValue Type Cast it into SPFieldUserValue and get corresponding lookupid and value for making the URL and showing Text of the HyperLink.
I have spent a lot of time on searching and bringing the HyperLink as the user name with navigation insted of UserID (27) as a string on the list view pages e.g AllItem.aspx but to no avail, then after a lot of research I found that there might be a way of achieving such kind of functionality by using field type definition xml file where there is a provision to define a DisplayPatteren as you wish by specifying the html code. But here is a problem How can I get the UserID (27) with respective UserName e.g In-Wai-Svr2\tjagtap inorder to make an anchor tag like In-Wai-Svr2\tjagtap which will solve my problem. I have hard coded this anchor tag within the Default case statement of a switch under DisplayPatteren but it shows me the field value on AllItems.aspx as
In-Wai-Svr2\tjagtap27 i.e the value defined in xml file is concatenating with the string value (27).
Please help me to resolve the above mentioned 2 issue. I am really in need of solving this problem ASAP.
Thanks & Regards,
Tejas Jagtap
Have u tried to override the GetFieldValueAsHtml() method in the the custom field class or maybe the RenderFieldForDisplay() method in the custom field control class.
Can you use the DisplayPattern CAML from the User field type?
I have added a menu item in edit control block(ECB) in document library(using following msdn article http://msdn.microsoft.com/en-us/library/ms473643.aspx)
Now i found that the custom action(menu Item) in ECB is displayed for both document item and document folder. So how to apply custom action only for document item?
Are you using list as your RegistrationType?
Try using ContentType as your RegistrationTypeand specify the guid of the Document Content Type (I think its 0x0101) in your RegistrationID.
You will need to create a class which inherits from WebControl. This class will need to render out your menu item as you want it displayed.
You then need to use the ControlAssembly and ControlClass parameters from your CustomAction definition to specify this class.
Your class will need to detect the if the current item is a document or folder and render/not render itself accordingly.
I would get the control working first just displaying a link, then add the logic in later.
This is a good blog posting on the technique, its not for the ECB but the principals are the same.
Enjoy!
In your customAction use RegistrationType="FileType" to determine FILE and use a RegistrationId="doc" to determine a extension, my exemple use word document. ;-)