MVC 5 Use a shared header and footer layout across a site that loads different models on each page - entity-framework

I am trying to create a universal layout across my site. The layout is made up of the header and footer from 2 separate files. I have a file for the header called _LayoutHeader.cshtml and a file for the footer called _LayoutFooter.cshtml. I want all the pages to use this layout so that I do not continue to have repetitive code like writing the navigation menu and scripts that are in the head section and footer sections over and over on each page.
I load the header on all my pages by using the following at the top of the pages.
#RenderPage("~/Views/Shared/_Partials_and_Views/_LayoutHeader.cshtml")
The footer is loaded like this by me calling it at the bottom of all the pages.
#RenderPage("~/Views/Shared/_Partials_and_Views/_LayoutFooter.cshtml")
The _LayoutHeader.cshtml file contains the dropdown navigation with all the required links and all the CSS references, bootstrap references, scripts for APis that are involved as well as valuable SEO tags like description, title, index follow and no follow etc....
The _LayoutFooter.cshtml file contains more links that also navigate to different pages depending on where in the app you are clicking it from. If my client A clicks on his link called Files, he will see different content from my Client B and Client C that also click on their links called Files. So I use models to handle these clicks on those links.
These 2 files also include the call to a model that is used across the site.
#model MultiCMS.Models.tblClient .
There are some pages though that use a different model like this one:
#model MultiCMS.Models.tblProducts
How am I able to use that layout (the header and the footer combination mentioned above) on pages that call a different model on? By "model" I mean I am using entity framework and in order for me to load the data that I need on each page. I call these models at the top of the page to grab and display the data.
The issue I am having is that when I am trying to use that combo of the 2 layout files, its failing on the pages that are not using #model ClientsApp.Models.tblClient. Like in the case of the pages that use #model MultiCMS.Models.tblProducts it fails but works on other pages that use #model MultiCMS.Models.tblClient .
Error:
The model item passed into the dictionary is of type 'System.Data.Entity.DynamicProxies.tblProducts_A96074721A46B7C99112D6FEA49F0762848C8', but this dictionary requires a model item of type 'MultiCMSApp.Models.tblClient'. If I want to use the same layout on all the pages but some have different models than the layout pages what do I do ?
This is a web application built on asp.net MVC 5.

Related

Doxygen Separate Navigation/Hierarchy Page

I'm setting up Doxygen in my codebase and want to use the Markdown support to produce a number of different 'how to' and 'design' types page in a logical hierarchy, e.g.
index.md
design/
architecture.md
database.md
how-to/
build.md
restore-backups.md
...etc...
Using the Markdown support, I can give labels to each page and then use those to link to other pages and create a page hierarchy, e.g.
Design {#design}
======
This section contains design documentation.
#subpage architecture
#subpage database
The problem I've got is that this means every level in the hierarchy needs to define which pages are its sub-pages. This litters the documentation with lots of links which I don't really need. When the hierarchy gets 3+ levels deep you end up with lots of dummy pages which only exist to define the subpages.
My question is, is it possible to define the entire navigation hierarchy in one external page so that I only have one place to define and update when new pages are added? Something like:
Navigation {#navigation}
=========
This page defines the navigation tree for the whole project.
#page design
#subpage architecture
#subpage database
#page how-to
#subpage build
... etc ...

How to change the website look and feel by changing the design location under page properties

I have a requirement where I have 2 clientlibs having different CSS files for my website. The business author should be capable of switching the website look and feel by just changing the path of the design under page properties. While I am able to achieve that requirement by changing the clientlib categories name referred in my JSP of base template of my site, can the same thing be achieved by the business author without actually performing a code level change? Basically, he should be able to select the design path present under the page properties section, and selecting a different design should change the look and feel of the website. Please let me know how this can be achieved.
Note: I have placed my clientlibs under /etc/design/proj-name/ path
The foundation page component is designed to include css link in the head if a file called static.css is present under the design. It's done through the design object.
If you have different css in the static.css file under different designs then the look and feel will change with the design. However you will be stuck with one file and cannot leverage the utility of client libs.
This adobe doc suggest's doing something like this for css and related images
<%= currentDesign.getPath() + "/static/img/icon.gif %>
Data from design dialogs is stored under the design , swapping designs to change look and feel will cause data inconsistencies too.
Why not add a selection widget to the page and use it's value to selectively include different client lib categories instead of relying on the design.

CQ: Content centric OR page centric?

I have a query regarding CQ. Your reply will really make the difference to my understanding.
In other CMS like Vignette, content authors create the contents separately (not directly on the page) for ex. products details and then those contents are iterated / processed to display on the page. But in CQ, the scenario is other way round. Authors directly create the content on the page. Now if same content is needed on other page, how will that be re-used ?
Regards,
Ronak
Content can be reused across pages via Reference components. From the docs:
The Reference component lets you reference text in another part of a
CQ based website (within the current instance). The referenced
paragraph will then appear as if it was on the current page. Instead
of referencing a specific paragraph, the path can also be modified to
specify an entire [paragraph-system]...
There are some other techniques for sharing content and reference data across pages, including inheritance and "data components," described in this SO Q&A.

How page activation take place for pages containing inherited component i.e components dropped in iparsys?

I have created a website structure in CQ5 WCM. I have created one template and defined few parsys and iparsys into its page level component. After this i have created one page and several more pages under it. Now my question is if make changes to the iparsys component and activate it, would all the pages inheriting it will also get activated or i need to activate all the pages individually?
Yes, all the nested pages would pick-up the change. Look at it as a "computed" reference - your page containing the original content gets replicated to the publish instance's repository, and all other pages compute their HTML based on that indirectly-referred content.
Dispatcher's cache however is another beast - make sure you're invalidating whole site's cache, rather than just the page you activated.

Programmatically creating menu hierarchy in Joomla

Let's say that I have a vast quantity of restaurant reviews in a database -- not Joomla articles, just database tables. I want to display these restaurant reviews as part of a Joomla 1.5 web site.
I can write a component to display each review. That part is fine. But rather than listing the reviews as a list on a page, I want to use the nice cascading menu that is part of the Joomla template that the site uses. But I don't want to have to add menu items one by one for each review; I want menu items to be generated automatically from the database contents. The menu of reviews should 'plug in' the existing menu structure for the web site (i.e., I want to supply the code that generates the menu items with an existing menu item so that it generates itself under that item).
How can I create code to programmatically create that menu? Component, plug-in, module, ...? Would the menu be generated at page display time, or "manually" in the admin panel (I'm ok either way). Any examples of this already?
I think the simplest way would be to create a custom menu module. The absolute basic one would just output the list of reviews in a <ul> and then use some css to style the list.
I ended up creating a component that creates the whole menu structure at once, upon admin request. It just creates rows in the jos_menu table, as if the menus were created manually. Updating the hierachy is a pain (and I haven't completed that part), but creating the structure from scratch is pretty simple and works well.