Im a new user of MODx, and the way to approach the whole ’building a website’ process.
I could use some advice on how to build the following.
I have list of data in a database table. To simplyfy, lets assume it contains four columns, name and description, origin and size.
I want to have two kinds of pages.
One page to list all entries in this table, showing name and description in a list.
[table]
[tr][td]name1[/td][td]description1[/td][/tr]
[tr][td]name2[/td][td]description2[/td][/tr]
[tr][td]name3[/td][td]description3[/td][/tr]
[/table]
If you then click on a row in this table, you see another page, with detailed information about the row, displaying all the data layoutet in a nice way (template)
I am not sure what the "right" way to do this in MODx. I know that all things can be done in a milion ways, but when you havent fully understood snippets, chunks, modules and plugins - its hard to start out, and I want to start out by doing this the MODx way, and learn from there.
I also want to build the site with as little mix of layout and logic - to keep them seperated as much as I can.
I can build the first page using a snippet that queries the database and, using a mix of PHP and html, outputs this. However, I have a feeling that this is not the best way to do it.
Also, how would I build the links for the table, to load up the detailed page based on the ID of the row you click? Do I make a set of TV that each fetch the data I want. So that I have one TV that fetch the name, one for description, one for size etc? Doesnt that make alot of unnessesary queries to the database?
I have used other CMS software where you can have your logic in one place, and the template html in another, and then just parse the html template, replacing the tags you have defined, I am sure that you basically do the same thing in MODx - only I havent figured out how to streamline this process?
Do I really have to code alot of snippets/PHP in order to fecth things from the database and output them in a template?
This is how I would do it. Create 2 pages.
1. Summary (example ID is 5)
2. Details (example ID is 6)
Instead of echoing the text, parse a ’chunk template’ with
foreach row {
$my_chunk .= parsechunk('thechunk');
//For the links:
//Create a link (use modxapi) with id=6 and add &view_details=$row_id
}
setplaceholder -->mychunk //this is pseudocode
In your summary, call your placeholder [+mychunk+]
For the Details page
Create your snippet to grab the &view_details, and do the parsechunk again.
For a really good example of this, checkout ppp. It’s not supported anymore but is a really good example at using the modx api to retrieve info from a database, parse the info in a chunk, and return it. PPP is here -
http://modxcms.com/forums/index.php/topic,8922.0.html
Edit: This is very rough and just gives examples of how to setup the ’idea’. You’ll need to look into the api to see how to implement it correctly.
-
☆ A M B ☆
- 24,524 Posts
I thought of a chunk as a piece of static html you could insert anywhere you wanted on a page.
That’s exactly what it is, even if you want it inserted repeatedly in the same page. Ditto and Wayfinder both use chunks as templates for their listings. The trick is the use of placeholders in the chunk to be replaced by the looping snippet at each iteration.
If you’ve got time, you might want to look at using TVs and Ditto- but I feel this will be more of a learning curve for you.