MODX Access page content from snipet - modx-revolution

I have a parent page where I want to load through a chunk the content of several child pages just like in a blog roll:
Child1 content is text : Text for page Child 1
Child2 content is text : Text for page Child 2
Child3 content is text : Text for page Child 3
What I don't know is how to access the content of Child1, Child2, Child3 pages in the chunk. I tried like this [[~id_of_each_page]] but it didn't show anything.
Any thoughts on this, guys?

I know this is an old question, but getResources (the extra) is made for this. You can use it to specify what children, or what parents to list content from. It is also very customizable so you can include template-variables or anything you like, order, limit and so on.

I found out the answer : I should call these snipets from the parent page :
[[getResourceField? &id=`6` &field=`content`]]
[[getResourceField? &id=`7` &field=`content`]]
[[getResourceField? &id=`8` &field=`content`]]
Obviously you have to get first getResourceField from extras.

Related

Multiple pages, single controller, how to set it up in mvc?

I have a 'home' controller which deals with the basic Home, About, Courses, Contact pages. There are multiple courses available, each with their own page and I would like to know the best method for referencing these pages. I could just create them as additional pages and add an actionresult to the home controller for each page. So the url for a course would be home/course1. Presumably there is a much better method than this though.
Ideally I'd like to have the individual course pages in a separate folder within the view folder and their url to be /home/courses/course1. Can anyone explain the best method using MVC for organising these pages?
So it goes like this : There will be a single page for all the courses and all the course pages will be partial views now there will be a div on the main page and whenever user clicks one of the course name.. it will fire an ajax request and it returns the required partial and populate the div with the returned content. You can give a common class to all the links of Courses, just like this :
.<a class="couseTrigger" data-source="#Url.Action("Name of Partialview action,"
name of controller")">
------ Script -----
$('.couseTrigger').click(function(){
var _this = $(this);
var url = _this.data('source');
--then make the ajax request to this url pvariable and retrun the partial view.
});
If you have multiple courser avoid creating multiple webpages for those courses. Rather have the content of each course stored in a database and retrieve specific course content by some parameter and bind it to the webpage. Creating webpage for each course is not feasible. Suppose you have 100 courses are u gonna create 100 webpages ?

Pass URL to new View as a parameter

I've spent a couple of hours trying to work out a way to do this. It's such a simple requirement that I can't believe I need to create view models or anything so grandiose.
Very simply, using MVC5, I have a View, let's call it Page1, on which there is a hyperlink. When the user clicks that hyperlink, I want them to be taken to a new View, Page2. On Page2 is an iframe. I want to set the src attribute of that iframe to the URL of Page1, the View that the user was redirected from.
So, if I could maybe use the ViewBag (which people on here don't seem to recommend), to pass the URL of Page1 from that View to the Controller for Page2, and then use Razor in my markup on Page2 to define the src attribute of the iframe, I imagine that'd work fine. Unfortunately, people don't seem to like using ViewBag, and also, I can't find an end-to-end description of how to actually achieve this in code.
Can somebody give me an appropriately straightforward solution to this problem?
A ViewModel for a View can simply be a string - so if you only need to pass a single value in to the view (the URL to use as the src), then in Page2.cshtml, you just define the model at the top like so:
#model string
To use that as the src attribute, you just do e.g.
<iframe src="#Model" .... >
And from the controller, you pass the url string as the model to the view like so:
return View("Page2", myUrlStringVariable);
So, to recap, a ViewModel doesn't necessarily have to be a new class you create - for the most basic scenarios like this, you can just use e.g. a string as the ViewModel. As soon as you start having multiple bits of data to pass in to a View, that's typically when you'd look to create a specific ViewModel class.
Another option may be a JavaScript solution. Something like...
document.getElementById('myIframe').src = document.referrer;

Wrong JSF 2 ID Chaining

Situation
JavaServer Faces Version: 2.1.6
I got a parent composite component with two nested cc. One of them contains a HtmlPanelGroup, which has a component binding. I use that binding to programmatically add HtmlCommandLink-Objects to the HtmlPanelGroup.
Let's call some IDs:
PARENT for the parent cc
CHILD_FIRST for the first child cc, nested in PARENT
CHILD_SECOND for the second child cc, nested in PARENT
GROUP for the PanelGroup, nested in CHILD_SECOND
LINK_1 for the first HtmlCommandLink-Object, progammatically added to GROUP
Expectation
I expect the following ID Chaining (with default javax.faces.SEPARATOR_CHAR):
PARENT (Composite Component, declarative)
PARENT:CHILD_FIRST (Composite Component, declarative)
PARENT:CHILD_SECOND (Component Component, declarative)
PARENT:CHILD_SECOND:GROUP (HtmlPanelGroup, declarative)
PARENT:CHILD_SECOND:GROUP:LINK_1 (HtmlCommandLink, programmatically)
Problem
The ID of the HtmlCommandLink-Object is wrong at the first page visit. Instead of "PARENT:CHILD_SECOND:GROUP:LINK_1" the ID is only "CHILD_SECOND:GROUP:LINK_1". After I refresh the page the ID is correctly "PARENT:CHILD_SECOND:GROUP:LINK_1". In fact every component in the second composite component ("CHILD_SECOND") is missing the first part of the ID ("PARENT"). After refresh all IDs are correctly.
Solution
I might automatically refresh the page after the first visit. But I don't want to.
the id after interpreted by the browser doesn't like what you thought. as far as i know it doesn't exceed 3 levels. For example:
<h:form id="form">
<h:panel id="panel">
<h:panel id="panel1">
<h:label id="lab"/>
</h:panel>
<h:panel id="panel2">
</h:panel>
</h:panel>
</h:form>
then the label's id will not be form:panel:panel1:lab but form:panel:lab. if the widget that you want to get the id is more deeper, then i can't tell but it won't exceed 3 levels. i can tell you how to find the id.
you can just write the page, and then view it on the chrome or firefox where you can see the source code after interpreted. so you can get the id you want.
good luck!

Displaying Grails domains in jquery tabs

What would be the best way to display data from Grails database in JQuery UI tabs? What I would like is to have a tab interface and on each tab is a list of the records from a different domain. For instance, Tab1 displays the record list from Domain1, Tab2 displays the record list from Domain2, etc.
I have the JQuery UI tab interface set up and working and am currently using createLink to call the method from the controller to return the model of the appropriate domain. The tabs look like this:
<div id="tabs">
<ul>
<li>Hardware records</li>
<li>Model records</li>
<li>Building records</li>
</ul>
</div>
The method from the controller looks like this:
def listHardware() {
[hardwareList:Hardware.list(), hardwareInstanceTotal:Hardware.count()]
}
I've also played around with rendering a whole GSP within the tab by using "render(view:'HardwareList', model:[hardwareList:Hardware.list(), hardwareInstanceTotal:Hardware.count()]", but that takes a VERY long time (at least 5 seconds) to load each time the tab is selected and is not at all ideal, especially if it were to take that long for each tab.
UPDATE
As noted in one of my answers to Rimero's answer below, I was able to use templates to display tables of my domains' data. I'm also trying to implement pagination on each tab using the tag, but each time I click on one of the pages to view another page, it takes me to the full template itself outside of the tab interface. Any thoughts on how to format the tag so that everything stays within the tab??
Here's my suggestion:
You can fetch everything at once in your controller in your index method for example.
You can implement your tab contents as templates
(g render template). Each tab == 1 template.
You can fetch your domain objects buildingList,
etc. from the index method of your controller.
The g:render template code for each tab may only need to be passed a map or a collection for rendering.
In this case you don't need hyperlinks to controllers endpoints. You just keep anchors to the tab(div id) as in the default example here -> http://jqueryui.com/tabs/.
UPDATED ANSWER
As you said that sending all the data at once takes a long time, you could fetch it asynchronously. If possible populate the data only for the first tab directly.
Create a business method for each tab, that will return the model as JSON, data is only fetched if not already retrieved from the server (Need to keep state or see for example if the tab id has some DOM nodes.
Using JQuery, when the DOM is ready, get the current tab and if you didn't fetch the data for the first tab eagerly, fetch it at this moment with the busy image spinning.
As soon as you select a new tab, you need to check if the data was already fetched, if not, you send an ajax call and your callback function populate the data in the tab div container for example.
Hope it helps.

Have master page label display last edit date of child page being displayed

i'm building an asp.net site with master pages. When visitors views a page, I'd like to show the date and time the child page was last updated. I'd also like to do this all at the master page level so no code for getting this information needs to be added to each child page.
Is this possible? what would be the best way to do it?
Thank you in advanced!
Page.Request.PhysicalPath will give you the physical path of the page.
And the FileInfo class can be used to get its last update date.
There are caveats if you are redirecting using Server.Execute or Server.Transfer, in which case there are several alternative ways of doing this, including the one described in the Remarks section of the MSDN documentation for HttpRequest.PhysicalPath.
Typically, this is what I put in my *_master.vb code-behind files. And I use a base MainMaster.vb class with the Public LastUpdate As DateTimeproperty.
Protected Overrides Sub OnLoad(e As System.EventArgs)
MyBase.OnLoad(e)
Dim fi As System.IO.FileInfo = New System.IO.FileInfo(Page.Request.PhysicalPath)
LastUpdate = fi.LastWriteTime
label_lastUpdate.Text = String.Format("{0} à {1}", LastUpdate.ToLongDateString(), LastUpdate.ToLongTimeString())
End Sub

Resources