I have created a content type with one content part in the dashboard, I want to create a template for this content part.
But I see shapes only for the fields of this part, not for part itself.
Is it possible to create templates for dashboard created parts?
Yes, it is possible. There is no difference between shapes from dynamic type and shapes from types defined from code.
However, if you want a shape to override, you need a shape in the first place. If the part got built from the admin dashboard, it won't emit a shape for itself, only shapes for its fields. You should probably write a proper part, using code.
Related
Here is my scenario...
Using Orchard CMS 1.7.1 I have created a custom Content Type named 'VistaImage' using the Orchard UI. This Content Type defines one field based on a Media Library Picker Field, this field is also named 'VistaImage'.
A Projection of groups of Vista Images are placed in the 'Featured' Zone as a Widget reference and works well.
Using the Shape Tracer on the resulting page(s), the shape hierarchy looks as follows:
Zone [Featured]
Widget
List
Content Alt: Content-VistaImage
Fields_MediaLibraryPicker Alt: Fields.MediaLibraryPicker-VistaImage
Media
Parts_Image_Summary
What I want to do is to provide alternative shapes from the Content shape downwards. This is easy enough for Content itself and for Fields_MediaLibraryPicker (as the Shape Tracer automatically provides applicable alternatives (as indicated above)).
My problem comes in providing alternatives for the Media and Parts_Image_Summary parts.
Looking at the documentation for Alternates on the Orchard web site, I thought that if I created a new shape in my Theme at at /Views/Parts/Image.Summary-VistaImage.cshtml this would get referenced, but it does not (though if I remove the '-VistaImage' the shape does get used, but this would, I believe change this shape for every Content Type, which is not what I want to do).
Any advice/direction on how I should approach this requirement would be apprciated.
Thanks.
From personal experience, when you get that low level in the shapes, alternatives don't work very well, if at all. The only way I best deal with those scenarios is to choose the next applicable shape above it, and do an if statement to determine if its the content you want, in which case to remove the default shape display and implement your own hard-coded layout.
eg if the shape simplay says #display(Model.whatever) and you know that displays is garbage for you, look into the model.
For example, I had trouble creating a 4 leveled menu for bootstrap as it only typically deals with 2 levels, so i manipulated the lowest level shape. I.e:
if{Model.Items.Any()}{
//code to generate another submenu for that menuItem
}
This may not even be the most correct way to address this, just the solution I found has worked.
So in your case I'd use VS debug and breakpoint where the mediafield picker is rendered, and find out if the model holds any information letting you know it's your VistaImage content.
Hello fellow Orcharders!
I'm not sure if what I want to do is possible, but I want to override the Driver for a single Field in the Module I'm writing.
The Field I want more control over is the Content Picker field. Basically I want the Content Picker to load the shapes for their respective content items. I've looked at Sipke's Content Picker Widget for an example on how to load shapes, however I'm unsure of the best/recommended approach to implement something similar in my module.
I have the Content Picker Field attached to my Content Part, and the default Content Picker comma list of Content Item titles appears as expected. I have tried to define an Alternate in Placement.info, but I can't load the Content Item shapes from within the Alternate view.
Presumably, as per Sipke's example, these shapes need to be built in the Driver and passed along. If this is correct thing to do, how could I do this in the most Orchard-y way with minimal "hacks". Looking into the debugger, I could "hack" my way to the Field I need in my part's Driver; but the module I'm building will be reused in the future by people unfamiliar with it, and if they start adding/deleting Fields from the Content Part, I'd like everything to behave accordingly!
Of course, if I must take the "hacky" option, I'm willing to do so, but only after I've exhausted all other options. This is my first module, and I've learnt an incredible amount along the way, and I'm really trying to learn the "right" way to build an Orchard Module as best I can.
Thanks in advance!
I would like to know if it is possible to use kentico macros (not necessarily coding a custom one) to access part of the rewritten URL's Path.
Example: http://www.mysite.com/Category/Subcategory/
I would like to get the last part (Subcategory) so that I may then filter content dynamically. The reason I want to use the macro is to simply not have to have 20+ different page templates only so I can have different web part properties.
Assuming you are using Portal templates, and you don't want an 'all items in all subcategories' list on the parent:
Create an Article List web part on the parent page — parent to all the sub-categories.
Set the web part Path to /{0}/{1}/{2}/% (if your path was /Home/Parent/Subcategory for example) or something similar for your environment.
Use the default setting of Inherit for the page template for all subcategory pages.
This will not show anything on the parent page, and the sub-categories will show only the documents under themselves. Note: If you want the subcategory items to have their own views when user digs down to /{0}/{1}/{2}/item, you may need to filter by changing template inheritance, or Document Types on the web part, or something like that if you don't want the whole sub-category list to also show on the item-specific pages.
You can create a custom macro or, you can also use the string operations which are allowed within macros. Please see http://devnet.kentico.com/docs/6_0/devguide/available_macro_methods.htm#string_methods (and you can e.g. use the EndsWith or TrimStrart or something similar).
However, I think the best way would be to create a custom macro which will exactly fit. There might be some combination of macros and macro functions - but I think it is faster just to code a custom one which will cover your need 100%.
Also, you can take a look on the K# if there is something that will fit - http://devnet.kentico.com/docs/6_0/devguide/ksharp_syntax.htm
I'm doing some work on an existing SharePoint site and part of what I need to do is create a new field on an existing content type.
I'm going to be deploying changes via a feature so I'm debating whether I use CAML to generate the field and then programmatically add it to the existing content type, or whether I can just do it all via the feature receiver.
What would be the best/ cleanest (and most reusable) solution for doing this?
A simple way is to do it in the feature receiver, get a reference to the SPContentType, add the field as XML (SPContentType.Fields.AddFieldAsXml) and then update pushing the changes to child content types
It is really tricky to modify content types on a site that already exists. My preferred method involves having a solution for all the content types and re-deploying that solution when changes are made.
I am going to go on the assumption that by field you mean a new Site Column. In this case I would do it all in the code behind. The amount of code that you need to write to create a site column is rather minimal. You can also attempt to remove the Site Column from any Content Types that are using it if you wish, but this is a task that is quite more involved.
From a reuse perspective if you set-up properties in the feature.xml file you can use those to configure things such as the column name, column type, target content type, etc. and then have a class that can be re-used in the future.
Have you looked at http://msdn.microsoft.com/en-us/library/ee537575.aspx, in particular the < AddContentTypeField> tag? That would be a declarative way to do this.
I have a custom SharePoint application page deployed to the _layouts folder. It's a custom "new form" for a custom content type. During my interactions with this page, I will need to add an item to my list. When the page first loads, I can use SPContext.Current.List to see the current list I'm working with. But after I fill in my form and the form posts back onto itself and IsPostBack is true, then SPContext.Current.List is null so I can't find the list that I need to add my stuff into.
Is this expected?
How should I retain some info about my context list across the postback? Should I just populate some asp:hidden control with my list's guid and then just pull it back from that on the postback? That seems safe, I guess.
FWIW, this is the MOSS 2007 Standard version.
Generally speaking I try and copy whatever approach the product group has taken when looking to add functionality of my own. In this case they add their own edit/view/add pages via the list definition itself.
I built a solution that also needed its own custom "New" form, not open source unfortunately, though if you are interested you can download it, its called "Tagged Links" (Social Bookmarking for SharePoint) and you can find some links on my blog.
To give you a few hints and tips, the following should set you off in the right direction:
Created a new list definition.
Created a new Content Type In the content type you can define your own "FormTemplates" that references a Rendering Template which determine what gets displayed in the "Middle" bit of those forms.
Copied the standard Rendering Template, but then made the changes to it that I
needed.
Wrapped it all up in a solution, and deployed.
My Rendering Template actually included an overridden "Save" Button where I did a lot of the extra work I needed to do during the save.
Anyway, it is a little too much work in my opinion but, I think, it most closely matches the standard approach taken by the product developers. Let me know if you need more detail and I will see if I can put together a step-by-step blog post, but hopefully this gets you off on the right direction.
I would be surprised if you could do something in a _Layouts file that you can't do in a forms template. You have pretty much the same technologies at your disposal.
Looking at the way SharePoint works with ListItems and Layouts pages (for example "Manage Permissions" on a list item), I can see that they pass some variables in via querystrings:
?obj={76113B3A-FABA-4389-BC85-4BB2CC5AB423},6,LISTITEM&List={76113B3A-FABA-4389-BC85-4BB2CC5AB423}
Perhaps they grab the context back each time programmatically using these values.
I'm not using a custom "new form", so this might not apply. I added an event receiver to my custom content type and then do my custom code in the ItemAdded or ItemAdding events. This code fires when the event is added to a list. You can use the event receiver properties to get to the parent List, Web, and Site.
I'd like to think my issue is "special" here, since I am using a custom form. I chose to use a custom form rather than a custom FormTemplate simply because I'm doing a lot of stuff that's not very SharePoint list-like (making ajax calls to get info from a third-party app then generating some dynamic form elements based on that ajax result, then subsequent processing of that data on postback). I thought it'd be a nightmare to try this within the usual custom rendering template mechanism.
I also don't think I can supply the custom form declarations in the list definition itself, because I have multiple content types associated with this list, and each content type has its own custom form (the other type is thankfully much simpler).
Actually, my simple way of keeping the list guid in my hidden field was a very low impact way to address this specific problem. My main concern is that I'm not sure why the SPContext just loses all its usefulness when I postback here, which makes me think I'm doing something wrong.