How to get the order of each List item in Orchard Cms? - orchardcms

I'm displaying a List of items in a widget container. This list have already been ordered using the dragable editor on the List container itself.
However, the Widget doesn't respect that order and have been trying to figure out the best way to do this. I'm getting the list inside the alternate shape template of the widget as
#{
IEnumerable<object> items = Model.ContentItems;
Model.ContentItems.Classes.Add("content-items");
Model.ContentItems.Classes.Add("list-items");}
#Display(items)
I'll like to know the best way to get the order that is set on the list so I can manually controlling the rendering and use that order.
Thanks

Related

Adding position to nodes in view results

In Drupal 8 I have a view that shows nodes in the result. What I need is to know the order that each node has in the results list. In other words: if my node template only shows titles of those nodes.
What i need to get is something like:
1 | The title of one node
2 | The title of some other node
etc.
I was thinking of making an override of the views-view-unformatted.html.twig. There, I can work with the loop, but how can I have the index of the loop in the node templates?
Don't really think you have to override anything here. You can create a new view mode for your node, e.g. teaser and manage its display using Display Suite.
Afterwards you can select rendered entity to show in your view and the corresponding view mode.
just play with the sort criteria of your view
it is all configurable in the back-office
/admin/structure/views/view/name_of_our_view
IMHO loop in Twig is good solution, but in order to add numbers to your node titles you can change format to HTML List.
In format section choose HTML List, save, then click on Settings and choose "Ordered List"
The result should be similar to this:

What should I use to view for nested data?

I want to list the faculties at the university.Then I want to list the departments at the selected faculty,then I want to list the lessons at the selected department.
Faculties>|selected faculty|>departments>|selected dept|> list of lesson
What should I use to view for this structure?Which datatable/uicomponent is more suitable for me? I use Primefaces 5.0 in the view layer.
Datatable
You will have to implement some listeners (i.e. to fetch your next list based on the selected value) but that won't be a tough task since PrimeFaces datatables provide selection features (row click, button, ...) Just look at the showcase links below to get an overview.
Showcase:
http://www.primefaces.org/showcase/ui/data/datatable/basic.xhtml
Master Detail
This is part of Primefaces Extension but seems to fit your needs because most of the logic is ready to use out of the box (ajax: update list view, update breadcrumbs, ...)
Showcase: http://www.primefaces.org/showcase-ext/sections/masterDetail/basicNavigation.jsf
Tree
Either horizontal (http://www.primefaces.org/showcase/ui/data/htree/basic.xhtml) or vertical (http://www.primefaces.org/showcase/ui/data/tree/basic.xhtml). If you want to display your data within a table, consider using the TreeTable (http://www.primefaces.org/showcase/ui/data/treetable/basic.xhtml).
However this will require to handle a TreeNode and it will, IMO, be way more difficult to build the TreeNode dynamically

displaying a list on screen with orchard

Using orchard cms 1.6 I have a table in my db 'cars'. I want to display the column 'CarName' from the table, as a list on screen with all the records from the table.
carname1
carname2
carname3
When the user clicks on their link it will bring them to that page.
I know how to do this from the view e.g.
#T("Cars")
but I would like to try and create a content type which shows this list.
Content type seems to be all UI related. Im not sure how to take a table and display a column as a list on screen through the content type...any idea on how to do this?
then I can choose to show the content type as a form and the user can view it from the main menu.
thanks
It looks like you want to create a content type called Car, possibly with a CarPart and a record class CarPartRecord (perhaps refactor your Car class to CarPartRecord to follow Orchard's naming conventions). Make sure CarPartRecord derives from ContentPartRecord.
To render a list of Cars, you could use a Projection that renders a list of cars. A Projection renders content based on a Query, which you configure using the dashboard.
Alternatively, you could create a controller that leverages IContentManager to query all Car content items, and returns a view to render them in a table.
For each Car content item, use Html.ItemDisplayLink to render a link to its details page.

How to show header of ListView when its empty

I am developing the following screen
The fourboxes next to each other are buttons. On clicking of the buttons I am changing the adapter of the listview.
Since the content above the listview took up lot of space I made the whole thing as an header and added it via code.
myPollsList = (ListView) findViewById(R.id.listArea);
myPollsList.addHeaderView(getLayoutInflater().inflate(R.layout.profile_listview_header, null));
Now I want to show some view when the list is empty. But if I do that then the header also goes away.
I am using this in a Activity and not a ListActivity. Any suggestions or workarounds for showing the header even when the list is empty ?
EDIT: Refer to my earlier question here ListView not getting space to show content on smaller screens . This is where someone suggested me to solve the problem by putting it as a header
I found a simple solution for this problem. If there's no elements for list and you are not adding the adapter, just add this:
mListView.setAdapter(null);
and the header will appear. It's easier than adding empty / fake item to the list.
So this is how I solved it. I had a custom adapter which was connected to the listview. When it found that it had zero items to display. It would add a fake empty view as an item to the list.
maybe you will like this Android addHeaderView disappears when no items in ListView
override/subclass your adapter to return false from isEmpty()
Don't use top layouts of button as header for list view.
So to adjust UI without using list header use weights.
Give parent Linear layout weight sum as 4 and 1, 1 to top Layouts and 2 for list view.

Custom theming Drupal 6 Menus

Is there a hook or preprocess function that I can access to write my own theming function for a drupal menu (in this case, primary links)?
I have a rather complex menu structure that requires a little extra markup than I'm currently getting by just rendering the menu items in a block (involving sub-menus with a little custom markup) and really need to get access to build the menu's content variable myself, ideally from an array that has all the primary links and their children in scope.
While it may not be the best solution, it is one that worked quite quickly and painlessly:
Drupal keeps a cached version of all your menus in the cache_menu table, I ran a this query to retreive a serialized string containing all the contents of the menu:
SELECT data FROM menu_cache WHERE serialized = 1 AND cid LIKE 'links:primary_links:%';
Substitute primary_links for whatever the name of your menu is and call unserialize on $row->data to get a structured array of everything you should need to build a custom menu.
I call a function in hook_preprocess_block that swaps the content of the menu block with my own and everything seems to be working fine.

Resources