Orchard CMS - dynamic query based on TaxonomyField of current content - orchardcms

I am looking into using Orchard CMS for an upcoming project and have hit a block. The site need to display articles of various types alongside a list of recent articles of the same type.
To that end I have:
Created a custom ContentType called Article which includes a TaxonomyField for ArticleType.
Created a custom theme with zones to reproduce the layout the customer requires. (Including RecentArticles.)
Created a custom widget layer to show/hide the RecentArticles zone based on the current ContentType. (I.e. the RecentArticles zone is only populated when we are displaying an Article.)
Created a Projection to show recent content of type Article.
I see that I can use the ArticleType taxonomy field to filter the source of the underlying query of part 4. However I need that filtering to be dynamic based on the ArticleType of the currently displaying content.
Is this possible? Is there an alternative way to reach the same result?
Thanks in advance.

Related

Liferay: Dynamically populate 'select' structure field

I am building a liferay theme, which has two columns side by side. The right column is where the web contents will be displayed.
My implementation aims to build a menu (left column) that gets the titles from the web content titles and builds hierarchy (parent, child) based on a 'select' structure field that I added to each web content.
So far I was able to build this system using
Liferay.Service('/journalarticle/get-articles'...)
and some javascript coding.
Now the 'select' fields i use in my structure have predefined hard coded options.
How can i populate dynamically this option list so that whoever is managing content will automatically have all titles from all web contents available to choose a 'parent' from? So far a developer has to update this option list each time there is a new web content added.
#chadct : AFAIK Liferay not provide this default functionality, this is not good practice to populate dynamically value in structure field. But you wanted to achieve that functionality, then there are 4 solution :
Add one text field in structure which contains articleId of your parent web content.
You can add related article for that web content and write some sort of code to get article which consider as a parent of that web content.
Create Select DOM options form template which hold the list of article according to groupId and render on web content view mode, then you can select parent content from there and update content expando with articleId of parent webcontent. Remember this contains AJAX post request. and only show that control who is admin or loggedin user or depends on Role. Refer AJAX post calling
Hook edit_structure.jsp and add your logic here as you want.
Note : last one is worst but also a solution, Remember you need to modify your current solution.

Autofilling Part Values in an Orchard Controller

I'm very new to Orchard (and ASP.NET MVC) and I'm having some difficulty wrapping my head around how Orchard part properties can be automatically set in a controller. I have a "Gallery" content type, consisting of the stock Title, Container and Owner parts. I'm creating a controller with a Create method that hides all of the details of the Container part since I'm going to set the default page length, the item type, et cetera in the HttpPost version of the Create method. My problem is I don't know how to set those values on the http Post.
My general plan was as follows:
I created a CreateGalleryViewModel containing the title and admin username, both as a string. IN the view those two are represented as form fields. On the submit, I could run TryUpdateModel in the controller to update the CreateGalleryViewModel with the form values. But then how do I update the Part properties? I think I'm supposed to run IContentManager.UpdateEditor(, this) but I don't think this ca, work because I never ran IContentManager.BuildEditor in the first place. Here's where I'm stuck because I don't see how the content parts get validated and updated properly.
Am I looking at this at the wrong level of abstraction? How do I make a simplified editor for my Gallery content type?
What you basically need to know here is the following:
You can build the editor of a content item with IContentManager.BuildEditor()
You can updated an item's parts' values from the POST data with IContentManager.UpdateEditor()
You can also access parts by "casting" content items with the As() method (needs the Orchard.ContentManagement namespace).
When you're dealing with content items because of their dynamic nature it's rarely a good approach to create a view model where you recreate some of the parts' properties. If you have such static view models for what's contained in a content item then you'll miss the extensibility and flexibility that comes with Orchard's content model. E.g. if you add a new part to that content type since you're using a static view model the new part won't be handled.
For a complete example of how to manage content items from code, see the Training Demo module.

Get listitems from Current Site

I am trying to create a Page Layout, that should have a lookup field. Lookup field should always get populated with a list's items.
This list will exist in all subsites, so whereever I create this page, list should get populated with listitems from current site.
I tried using site column lookup field, but it always point to list under top site and not the current site.
Any suggestion on how to make it work or better alternative? Thanks!
Let me know if I can provide more info.
The most straightforward solution I can think of is using a cross site lookup column and creating a seperate fields for each subsite. However, you will need to create and use different Page Layouts for each subsite.
You can use http://sp2010filteredlookup.codeplex.com/ for cross site lookups.
Solution 1 - Use http://sp2010filteredlookup.codeplex.com/
Use filtered lookup solution. So let's say you have your custom Page Layout and custom Page Content Type.
Every time you create new subsite, you should remember go to Pages list settings and edit Page Content Type by adding cross site lookup (with the same field "internal name").
So you still have one Page Layout (and one Content Type). But for each Pages library instance, Content Type contains diff fields (but with the same Internal Name). It will allow you run CAML queries and other things needed without any problems.
Solution 2 - develop custom sharepoint field type.
In edit mode, control will render "dropdown list" and populate data from list instance that is on current subsite. In the field settings you can have relative list url.
Solution 3 - hidden text field / js snippet solution
Page Content Type can contain hidden text field (it can contains selected field value in json format for example). Develop js snippet that will handle all the logic (rendering in edit/view mode, saving etc) and put it on Page Layout (aspx).
I would suggest to use solution #1 or #2.

Checkbox list in Orchard CMS

Is there any module in Orchard CMS that I can install to get a checkbox list? I checked in the gallery but could not find one. If there is none, is there is a workaround this?
I want to associate a product item with multiple categories (fixed set of categories).
Thanks!
EDIT :
I checked the Taxonomy module as per the suggestion. Now, I want to access the terms in the view. I have seen some posts where they can access it using
(IEnumerable<Contrib.Taxonomies.Models.TermPart>)Model.Terms
Using shape tracing, I am trying to figure out how to access the terms. My model doesn't have any terms field! I can access my custom type (Project) which has 'ProjectCategory' as Taxonomy Field. But there is no mean to view/select terms from there.
See attached screenshots.
Any idea?
I don't think there is a module specifically for checkbox lists, but it sounds like the Taxonomies module might be what you're looking for. You can add a Taxonomy field to your product content type, and define a Taxonomy for that field that contains all your categories.
Once you do that the editor page for your products will have a checkbox list (or radio select if you allow only one in the taxonomy field's settings) for the "Categories" taxonomy.
I managed to access the terms the following way :
IEnumerable<TermPart> assignedTerms = _taxonomyService.GetTermsForContentItem(contentItemId, "NameOfTaxonomy");

Create a list of pages in Orchard

Lets say for example, I have a list of products that each have it's own page... in what way can I create a single page that will list each product as it's contents as a list (with hyperlinks)? Not really sure how to do this directly in Orchard - or will I need to create a custom page / widget? Thanks for any help... new to Orchard and not sure how to tackle this.
You have a couple options. I believe the Orchard gallery at orchardproject.net has a module called Simple Commerce that may solve your problem. (it's simple so it might not)
(In the following section, I've tried to boldface the terminology words that are 1) are crucial to understanding how to use Orchard and 2) helpful in finding your way around the dashboard)
Another option may be first creating a Content Type--probably one named Product with some Fields describing an individual product. Price, SKU and description come to mind, but you'll be better able to describe your own products. Each Content Type in Orchard can be associated with any combination of Parts. You may have to research which ones you actually want for an individual product, but I'd recommend:
Body (this could replace the Description I suggested above) You could include any amount of HTML/script in this section to make your individual product pages look fancy!
Common (this has to be added when Containable is used)
Containable (this will allow the items to be listed)
Route (so you can link to a specific product)
This gives each product its own slug (URL)
Tags (to allow products to be categorized)
Now, you need to create a new List from the dashboard so you can display the products together (and inherit other features like pagination, etc). Be sure to select the Product Content Type in the Contains drop down list.
Then, you can start creating your Content (your Products) one by one. In the dashboard, click the new Product item and describe each new piece of Content.
Finally, you can link directly to this new List using the Products List's *slug*. You could (and might want to) add the Products List to your main navigation menu. Clicking the Products List and checking the "Show on main menu" box will automagically add a navigation button directly to this page. You could, of course, link to this List from anywhere using the slug (also found on the list's edit page)
This page, from the Orchard documentation pages describes more things you can do with a list of content like modifying the layout of the list, placing content fields in different places and even converting your products to widgets which you could use to display some promotional product offering in a special spot on your site.
I highly recommend reading through at least the documentation provided on the Orchard site to get a good grasp of what this CMS can do out of the box and what you would need to write custom code to accomplish (which you could do in this case, but Orchard can handle it out of the box)
Hope this helps!
Two ways to do this:
http://orchardproject.net/docs/Creating-lists.ashx and http://orchardproject.net/gallery/List/Modules/Orchard.Module.Contrib.Taxonomies

Resources