How to access custom fields of a page in the theme template - liferay

I'd like to use custom fields to display some page specific strings in the theme.
I have created a custom field "intro" of type Textbox.
How do I access the data in the theme template (velocity)?
As there is no "introspection" which variables are declared, I find it very difficult to figure out how to access them. The documentation is far from usable on the topic of custom fields :-/

If you definde custom attribute in a page than you can use
$layout.getExpandoBridge().getAttribute("intro")
Also see javadoc or source for com.liferay.portlet.expando.model.ExpandoBridge

if you need use in template FTL, in my case for menu navigation template
<#assign prop = navItem.getLayout().getExpandoBridge().getAttribute("prop_name") >

Work for me in Liferay 7+:
Create a custom field type "site", fill data into site settings, and use into theme template for call this data into liferay theme:
If a VM file:
#set ($site_custom_field = $layout.getGroup().getExpandoBridge().getAttribute("site_custom_field_key"))
<h1>$site_custom_field</h1>
If a FTL file:
<#assign site_custom_field = layout.getGroup().getExpandoBridge().getAttribute("site_custom_field_key")>
<h1>${site_custom_field}</h1>
Have a nice day!

Related

How can I add extra properties to document metadata field types in Liferay 6.1?

I'm new to Liferay and I have the following situation:
I would like to add extra properties to document metadata field types in Liferay 6.1.20.
For example, I would like to add property 'readonly' to select boxes (see image), as it is a user requirement to show some controls disabled.
Should I use the Expando functionality, a jsp override hook or another approach?
I think Expando functionality, a jsp override hook are a good approach.But using Expando you cannot create it as mandatory field.

orchard cms: how to add media picker field to a custom part

My question is simmalar to questions/10369967/orchard-cms-how-to-add-media-picker-field-to-anew-module
I've created a new content part, that has a select list, a text box and ... I want to include a media picker filed.
I have added this to the content part with Bertrand Le Roy's suggestion of:
ContentDefinitionManager.AlterPartDefinition("Product",
builder => builder.WithField("ProductImage",
fieldBuilder => fieldBuilder
.OfType("MediaPickerField")
.WithDisplayName("Product Image")));
However I've no idea of how to show this in my custom editor View
I'm sure there should be something easy like #Display(Model.ProductImage) ... but I've followed the writing a content part form the Orchard docs, and my model in my editor view is not dynamic.
So if such magic as #Display(Model.ProductImage) exists, how do I add the media picker item to my view model ?
Update
The Media picker field seems to be showing on the content types where I add this part, just not where I want it! I want to show / hide this field biased on values selected form a select list, How can I stop the default rendering of the field Content Item and Render it in my custom view ?
Update 2
I've added this in the model
public MediaPickerField MediaPicker
{
get{ return (MediaPickerField)((dynamic)ContentItem).HeaderPart.Image;}
}
this to the view
#Html.Partial("EditorTemplates/Fields/MediaPicker.Edit", Model.MediaPicker)
and this is the placement.info
<!-- MediaPicker -->
<Place Fields_MediaPicker_Edit="-"/>
Now it looks right on the editing via cms end... but dosen't seem to save the images to the database!
Should be something like #Model.ContentItem.Product.ProductImage.Url

How can I present a library as a custom view?

I have a Sharepoint library that is currently rendering as the usual folder and document items table list view.
I would like to use present the same information as a grid of folder and document icons with some nice jQuery hover animations to show tooltips on the item the icon represents.
I suppose what I am really trying to find out is how to add a new library view that allows me to specify the markup rendered per item. I could write a new webpart to query the list and use an ASP:Repeater but I don't want to have to specify a webpart property each page to tell the webpart where it should open the list from.
You can use List View Web Part with custom XSLT.

SharePoint:FormField in a custom webpart?

On my home page, I want a simple webpart that allow users to quickly fill an entry in a list.
The list have, let's say, three fields : title (text), body (rich text), category (lookup).
I don't want to use the standard DataFormWebPart because I have a bit of code-behind that also fill some technical hidden fields of my list (actually, I don't exclude the DataFormWebPart, but I didn't find how to use it with code behind).
So I started to implement a custom webpart. Because I don't want to have to handle manually each field input, I started to use the FormField control, which automatically choose the rendering control, and provide a Value property with the correct format :
<SharePoint:FormField runat="server" id="fldTitle" FieldName="Title" />
This code is not sufficient, I have to specified the listid :
<SharePoint:FormField runat="server" id="fldTitle" FieldName="Title" ListId="{title list guid}" />
This is working quite correctly. I can in code access the fldTitle.Value to retrieve the user input.
BUT I have to include the webpart in a properly packaged and deployed feature, that can be activated. The webpart will always target the same list, but as the list is also instanciated in the feature (ListInstance element), I can't know the Guid in advance.
I've tried using several technics to set the list ID on the fly, but without success.
I've also "reflectored" the SP dlls to notice FormComponent class are using a "Context" that is set by ListFormWebPart.
Finally, my questions are :
is it the correct way to create a custom input webpart on the home page (not a list custom form) ?
how can I keep the behavior of the FormField (choose the right control and handle the input and its conversion to the storage format) ?
Will I have to create a custom ListFormWebPart ?
May I play with ControlTemplates ?
thanks in advance for the help... I'm struggling with this simple case for days now...
I think that customizing form templates is the easiest way to customize list forms. Since custom form templates are implemented as user controls you can add whatever code you want.
See the following article:
http://www.codeproject.com/KB/sharepoint/SharePointListForms.aspx

Is there documentation for the #Model type in Orchard?

I'm customizing my father-in-law's Orchard site and trying to create a .cshtml file to control the display of a Containable content type, but I'm having a bugger of a time finding the data in the #Model field. Is there any documentation on it anywhere?
So far I've found #Model.Slug and #Model.Title. What I'd really like is access to the custom fields on the Content Type.
The Model object is of a dynamic type so it's properties are dynamically added depending on what modules are being used.
If you are using the new 1.1.30 version of Orchard you can use the new Shape Tracing tool which is part of the Deisgner Tools module which can be installed through the modules gallery. This will add a panel to the bottom of your website page that will allow you to see and navigate through the Model object.

Resources