I have added a global site region to my site and filled it with some content. How can I read this content from page view and/or layout?
This feature differs a bit between WebPages & MVC, the reason for this being that in WebPages (like WebForms) a Layout-page have a different model than the actual page being executed. If you use WebPages you simply add the following line first in the Layout page:
#inherits Piranha.WebPages.LayoutPage
This will automatically load the layout page model and all the global regions.
If you're using MVC this can't be done automatically as the Layout doesn't have a model. You can simply add the following in your Layout-page:
#{
Piranha.Models.PageModel global;
if (HttpContext.Current.Items["Piranha_CurrentPage"] != null) {
var current =
(Piranha.Models.Page)HttpContext.Current.Items["Piranha_CurrentPage"];
global = Piranha.Models.PageModel.GetBySite(current.SiteTreeId);
} else {
global = Piranha.Models.PageModel.GetBySite(Piranha.Config.SiteTreeId);
}
}
This snippet loads the layout page from:
If it's a page is displayed it loads the site tree the page is contained in
If it's a post it loads the site tree from the current site.
Hope this helps you!
Regards
/HÃ¥kan
Related
I have an array of content coming from a database that will be displayed on a page as a group of FAQs. Some of the content will have links to other internal pages on the site. How do I link to the pages using Inertia's link component so that a full page refresh doesn't happen?
It depends on what is returned after using the link. If you return a full view in the response, the page is reloaded. If you return a small JSON object or something else, you can process it without full loading.
I tried to use the solution from https://stackoverflow.com/a/54043063/234954, to render a page as a string (so I can turn it into a PDF), but that only gets me the main view, it doesn't get the layout associated with the page (and so it is missing the style sheets and some header/footers).
How can I render the full page as a string, and not just the partial view?
I used this article code in a recent project to render html to feed into PDF generation.
I used templates in the Views folder so not razor pages.
It works with Layouts and partials in templates.
https://ppolyzos.com/2016/09/09/asp-net-core-render-view-to-string/
I found that I could get what I wanted (the whole page) by making two changes to the answer I was looking at:
var view = new RazorView(_razorViewEngine,
_activator,
new List<IRazorPage>(),
page,
HtmlEncoder.Default,
new DiagnosticListener("ViewRenderService"));
changed to :
var view = new RazorView(_razorViewEngine,
_activator,
pageModel.PageContext.ViewStartFactories.Select(v => v()).ToList(),
page,
HtmlEncoder.Default,
new DiagnosticListener("ViewRenderService"));
and
await page.ExecuteAsync();
to
await view.RenderAsync(viewContext);
Note that if the viewstart pages aren't included in the view, then rendering the view produces the same as executing the page.
I have a project I have attached Piranha CMS too. That bit worked fine.... However the pages I have already created and the template are not displaying in the CMS edit.
Steps I have done.
imported Piranha from guget.
Altered webconfig to passive.
removed piranha connection section.
changed connection to forms.
Alter connection string to match sql-server DB.
altered the global.config
built DB in sql server
Built project setup admin and the DB structure built followed.
Like I said it has built ok... But only the standard template. I'm guessing I've ether missed a step or there are steps to go. Can you advise me were to go next?
The webpage site currently just a home page.. The remaining pages are not completed. But if I don't crack this point there is little point continuing.
I think you have to add the pages into Piranha through the manager interface, then use the Permalink as the argument to fetch the Piranha managed content from Piranha. I don't think Piranha will parse your view/controller/routes and automatically import them into the site definition.
I use Piranha in my views like this;
#Html.ActionLink((string)Model.CMSData.Properties.WebSiteTitle, "Index", "Home", new { area = "" }, new { #class = "navbar-brand" })
I embed the CMS data into my model based on the examples in the Getting Started section;
public object CMSData = Piranha.Models.PageModel.GetByPermalink("my-permalink") ;
This enables me to weave in CMS content to my Model and then use it inside my View.
I have 100 web pages to my web site.
All web pages has links to other 99 pages.
If i want to add one more page to my web site i have to add new page link to all other page. I want to keep all page link at one place.
So that i can render all Navigation links from that section.
How can i archive this in MVC 4?
My Number of pages are growing day by day.
I am not sure if I got the question right, but will the use of MasterPages help you out here?
http://msdn.microsoft.com/en-us/library/aa581781.aspx
this this and this must help you
Keeping all the links in _Layout.cshtml and calling the _Layout.cshtml in all pages is the solution.
To call the _Layout.cshtml in other pages use.
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
I'd like be able to create instances of jQuery mobile pages using an existing jQuery Mobile page as a template. Can anyone point me in the right directing on this. Does anything exist along the lines of:
var pageInstance = new $mobile.createPage();
If you sure your page is currently loaded into the DOM.Try with this,
var page = $('#PageId');