0

Sorry if my question is silly but I'm new to DNN/2sxc, I've spent the whole day trying to figure this with no success..

I have two instances of the same app, one in the home page and the other on its own page, each one must have its own view template (I use Razor).

My problem is I cannot figure a way to make the two apps read the same data, so every add/edit/remove/re-sort in one of them will be reflected to the other, currently each app has its own data and therefore they are unusable in my case.

I've tried to use a 'EntityTypeFilter' inside a 'Data Query' and use it in both views (as in the News-Simple demo video), it worked and gave me all the items in the two views, but another two problems come with this solution:

1- now I'm unable to use the toolbar to (add/remove/reorder,.. etc) any of the items , as you can see in this image, which is a show-stopper for me,

note: this is the toolbar I use:

@foreach(var item in AsDynamic(Data["Default"]))
{
...
@Edit.Toolbar(target: item, actions: "new,edit,replace,remove,moveup,movedown,instance-list")

2- the 'Content Demo Item' is also visible in the list, but it is not that important since I can delete it and use one of the real data items as a demo item.

I appreciate any kind of help. Thank you.

Amer
  • 468
  • 1
  • 5
  • 15

1 Answers1

1

So the first thing you should know is the difference when using content-items as data (to query, etc.) and when using it as assigned-items (where each module-instance has a subset of items). Here's the blog that should help you understand the difference: http://2sxc.org/en/blog/post/12-differences-when-templating-data-instead-of-content

So when you want the "manually and easily control the exact items displayed, their ordering etc." you want to use the "content-assigned-to-instance" which also gives you the simple add, delete buttons, as these don't really delete anything, but just remove the assignment from the module-instance.

Now your case is a bit special, in that you want to re-use the exact same set in another module-instance. There are a few ways you can do this:

Same View

if it's exactly the same view etc. just duplicate the module using DNN-features (the add-existing-module-to-another page)

different view

if it's a different view (maybe more compact, etc.) you again have multiple options. The first is to mirror / duplicate using the dnn-feature, and just put an if-im-on-this-page-then-show-differently or inject another CSS. That's probably the easiest without any dev-know-how.

The harder, but possibly nicer way, is to actually to use a new template, and tell it to retrieve the items in the way they are configured in the other module - let's say module 1 is the original, module 2 has a different template wanting to access the items of module 1 in exactly the same order as given in 1. They way to do this is simple, but requires a few lines of C# code in Module 2.

You need to create a new ModuleDataSource (https://2sxc.org/en/Docs/Feature/feature/4542) object and tell it that it's from Module 1. If you've never done this, it's basically that your code can create a query just like the visual designer, but you have more control - see the wiki https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All. The Module-Data-Source in the visual-query-designer doesn't allow you to "switch" modules (a advanced setting we may add in the future) but the object has a ModuleId property which you can set before accessing the data, making it "switch" to that Module. here's the Pseudo code in your Module#2 razor...

var otherModData = CreateSource<ModuleDataSource>();
otherModData.ModuleId = 1;

foreach(var itm in AsDynamic(otherModData["Default"])) {
    ...
}

That should do it :)

iJungleBoy
  • 5,325
  • 1
  • 9
  • 21
  • Creating a new ModuleDataSource with a specific ModuleId is exactly what I was looking for, it now displays all of the items from the original module. thank you very much for the detailed answer. – Amer Feb 21 '17 at 10:35
  • while the (add/edit/..) toolbar is now visible on each item on the second (not the original) module, it seems that all buttons actions are targeting the data source of this module (not the original one with that id in the code), so adding a new item will add it to this module data source and will not be visible again, the same goes for remove, edit, etc.. is there any way to make sure that the actions are targeting 'mainModuleDS' (the datasource of the module with the specific id) ? – Amer Feb 21 '17 at 10:48
  • @using ToSic.SexyContent.DataSources; @{ var mainModuleDS = CreateSource(); mainModuleDS.ModuleId = 562; } @foreach(var item in AsDynamic(mainModuleDS["Default"])) { @Edit.Toolbar(target: item, actions: "new,edit,replace,remove,moveup,movedown,instance-list") } – Amer Feb 21 '17 at 10:48
  • When you are in Module 2, then edits apply to Module 2. You can use data from Module 1, but this doesn't change the context. If you really want full editability on both cases, you'll need to use the same module and conditionally change how it's displayed based on the tabid or something. – iJungleBoy Feb 22 '17 at 14:12