I'm building a multilingual Sitecore site and using Glass Mapper as the ORM, but running into an issue when the sitecore item doesn't exist in a particular language.
Rather than having a null model being passed into the view which I could check, I'm getting:
The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'foo'.
This exception is happening on the placeholder line rather than in the particular view.
Specifying a model against for each rendering seems to solve the issue for renderings where a datasource has been specified (although doing this results in a model having an instance but every property is blank). But if the data source is the regular context item I get the error:
Could not locate item containing model definition. Model path: /sitecore/layout/Models/foo
Any ideas?
Related
I'm working on a multilingual module right now and having problems with parsing a field to InternalLinkField. What happens is that I have an item in Chinese language, but when I get one of its field and convert it to InternalLinkField the converted item becomes English. Here's the sample code:
var field = (InternalLinkField)InnerItem.Fields["Test"];
So, the current item that I'm working on is the InnerItem, it is in Chinese version and when parsed the field object becomes English. So, as a workaround for now I used the context item to get the field with the language.
My workaround:
Item item = Sitecore.Context.Database.GetItem(field.TargetID, InnerItem.Language);
But, it is redundant and I want to know the right way to get the field object with the correct language version.
InternalLinkField is a system type used by Sitecore core. Hence, it is not recommended to use it for your custom features development unless you plan to extend Sitecore considerably. If you want to implement a link field in your data template then the following two types will be suitable for your need:
LinkField if you want to cover both internal and external links, i.e. admins can either select a Sitecore item or specify an external URL; you can simply use GetFriendlyUrl() method to generate the correct link as
Sitecore.Data.Fields.LinkField yourLinkField = yourItem.Fields["Link"];
var yourUrl = yourLinkField.GetFriendlyUrl();
Droplink if you want to restrict only to selection of a Sitecore item, such field will store ID of the selected item as value.
If you had a boilerplate scaffold for a rails model document you would get one model, controller, view and a bunch of other files that I'm going to ignore for the moment.
Over time new features are added to the application and the document model gets a few more fields.
In my application, I am trying to have documents such that once they are archived, the data never changes (that's easy to do), however the view used to render old archived documents has since changed and will display things that wenr;t there when the document was archived.
Is there a way to associate each document with a version of the/a view so that not only does the data remain the same, but the way it is rendered is also the same?
Sure. You could just add a version or archive_version column to that table, set all the existing ones as view_version 1, and render eg. show_archived_v1.html.erb from your controller for those records.
For "current" records, you can detect that the archive_version is blank and just render show.html.erb.
As you get a new type of version that needs to be archived, just store them with 2 in the archive_version column, and render show_archived_v2.html.erb wheb displaying them.
Inside my custom save action, I iterate through the form fields (the AdaptedControlResult objects). Any form field which is a DropList (from any source -- manually entered values, or an item lookup) is returning a string value of System.Collections.Generic.List`1[System.String]
Now, it's important to know, it's not returning an actual List. It's returning a literal string with that value.
So, this call:
fields.GetEntryByName("MyFieldName").Value
Is returning the string: System.Collections.Generic.List`1[System.String]. Not the value of the dropdown. A string saying that's it's a List<string>.
I have confirmed the HTML of the form is rendering correctly. I have manually checked the inbound HttpContext.Current.Request.Form values as well...
HttpContext.Current.Request.Form["BGWnjkQqrE6w6sr31IgzrQ.Sections[5].Fields[0].Value"]
That is the correctly-selected value of the drop down (a Sitecore ID).
So, the data is getting output to the form correctly, and the inbound Request.Form data is also correct. Somewhere, Sitecore is deciding not to populate the selected value into the AdaptedControlResult object.
What's additionally odd is that for DropList field types, the selected value does appear in the Parameters property (inexplicably). I would just detect this and use it, but it's not consistent -- for instance, for textbox field types, the word "multiline" appears there.
All other field types work fine -- I have several text entry fields, and some radio button lists. It's just DropList fields.
What is the trick to getting this?
This is a known bug in Sitecore when using the WFFM module in MVC. You can find more details in this Knowledge Base Article - Incorrect data is saved for list fields in WFFM MVC.
The fix is listed on the kb article and depends on the exact version of Sitecore you are using. Sorry to provided a link only answer but there are multiple steps reqiured for the fix and the download for the fix is attached in the article.
I am building a custom Field in sitecore 6.5. This field will generate new items based on the item in which the field resides (it uses the item's name to generate folders) and I need to reference the item in which the field is being used. How do I get access to this?
My custom field inherits from the sitecore Sitecore.Shell.Applications.ContentEditor.File class, if that helps at all.
My question is similar to the one located here: How to get a reference to the currently edited item when inside a custom field in Sitecore
However, the question there was for a previous version of sitecore, and the solutions no longer seem to work (ItemID is not in the viewstate, nor is it filled by the pipeline).
Thank you!
Struggling with the same problem for several hours, I ended up decompiling EditorFormatter and found that this class has Method called SetProperties.
By reflection (!?) this method checks if your field editor has the properties "ItemID", "ItemVersion", "ItemLanguage" .... sigh
Ok, so by adding a public property 'ItemID' we have the item being edited
If i'm not mistaken, Sitecore.Data.Fields.FileField is a representation of the field's data in the Sitecore API. For instance, you would use it to retrieve the MediaItem or Src by casting an item's field like so:
var fieldSrc = ((FileField)Sitecore.Context.Item.Fields["My File Field"]).Src;
I don't think it's intended to be used as a custom field in the Sitecore client. Try inheriting from Sitecore.Shell.Applications.ContentEditor.File or just strait up Sitecore.Web.UI.HtmlControls.Control. As long as you have a public string ItemID { get; set; } property defined, Sitecore should populate it with the current item ID.
I want to ask you how it will be better to implement: using Sitecore WebForms for Marketers module or in standard .ascx sublayout.
So I need to implement huge form with dynamic dropdowns, date pickers, checkboxes, radiobuttons, etc. This form contains also dynamic adding new controls (see description in attachment above). So is it possible to create this form in Sitecore WebForms for Marketers module or it will be easier to write it as standard form in ascx.
This form will be saved to sitecore database.
Please answer if somebody have already done smth like this.
Thanks.
To my kowledge it isn't possible to do this out of the box with WFFM in Sitecore.
I guess the first question to ask is: do you or your customer want/need to be able to manage forms themselves without developer interaction?
If the answer to this question is yes, then you could try to implement this with WFFM, otherwise it may be easier to just implement as a normal sublayout.
EDIT
One other thing you could also do is to create a form, then use the 'export to ascx' function. You can look at the generated code to see how the data is written to the WFFM database - this way you can have your custom form functionality but still leverage the reporting functionality in the Sitecore client. If you have some decision tree-like logic for displaying the different fields you could probably drive this from Sitecore content items as well.
As per my knowledge you can create this form with the help of Web form for marketer but in this case you need to create some custom fields and update these fields as per your requirement.
To Create custom field create field under /sitecore/system/Modules/Web Forms for Marketers/Settings/Field Types/Custom location and in custom field define your created custom class and assembly.
You can update design by applying your custom css classes.
Class you can create under /sitecore/system/Modules/Web Forms for Marketers/Settings/Meta data/Css Classes location and apply class on specific control.