Hi,
I’m trying to figure out how to use Template Variables to display database data.
As an example, I have a content page and want to display the shop name, city and telephone from a DB table
My solution so far has been to...
- add new table to the modxfs database
- get the [*pagetitle*] (which is the shop name)
- create a ’getdatabase’ snippet and pass the shop name variable in as a snippet parameter (based on the code in
http://wiki.modxcms.com/index.php/DB_query_and_Placeholders)
- display the returned data using the chunk in the same example
(I’ll post this example to the wiki in the next few days.)
This all works fine but the big downside is that it doesn’t appear in the search results. Obviously I could write my own conventional search script and return the results from that (but lose the functionality of the search that comes with MODx out of the box)
So I want to do the same using TVs which I understand do search within the database. I have read the docs but am really struggling due to the lack of examples.
Anyone got any pointers please?
Do I use the @SELECT or @EVAL binding? Why would I want to use one in preference to the other?
Do I need to create a separate TV for each field e.g. [*tv_shopname*], [*tv_city*], [*tv_tel*]?
In this case would I need to have a custom SQL query for each (which seems really inefficient....must be a better way of doing it)?
Thanks very much!
Mark.