dobmat:
I don't have that line "field" in my template code. I see in the smarty console that there is no array $item but what is there is $_items. is that what I need to use?
Thanks.
No - you should not see $_items - you should see $item. $_items will only be set for your item_list.tpl file. I think it's important to take a step back here and try to understand what you are actually doing - without understanding what you are doing you're just going to be operating in a 100% "reactive" mode where you are making changes to things without understanding
why you are doing them.
In your profile.php file now, there should be 2 different jrCore_parse_template calls - one to "item_list.tpl" and one to "item_detail.tpl".
item_list.tpl - this is the template that is used when you are displaying a
list of items from the module. It will contain a smarty foreach loop where it loops over the $_items array - for each entry in the $_items array it will process the inside of the foreach loop one time. This is how we create a "list".
The way that the $_items array is built is by a call to jrCore_db_search_items() - this is the DataStore function that is used to get
multiple items, and order them, etc.
item_detail.tpl - this template is used to display the information for a
single item - not a list of items. There will be no foreach loop inside this template, and the data for the item will be in the $item array -
not $_items (since there is only a single entry). The information for a single item is pulled from the DataStore using jrCore_db_get_item() - since we
know the item_id we do not have to use the search function.
Since you are seeing an $_items array in your item_detail.tpl file, you are using the wrong datastore function to get the item.
The most simple profile.php "default" view should look something like this:
if (isset($_post['_1']) && jrCore_checktype($_post['_1'], 'number_nz')) {
$_rp = array();
$_rp['item'] = jrCore_db_get_item('module_dir', $_post['_1']);
return jrCore_parse_template('item_detail.tpl', $_rp, 'module_dir');
}
else {
$_sc = array(
'limit' => 10
);
$_rp = jrCore_db_search_items('module', $_sc);
return jrCore_parse_template('item_list.tpl', $_rp, 'module_dir');
}
Remember this is the most
simple profile router, and somethings to note:
1) we create an array called $_rp (replacement) that we pass into jrCore_parse_template - the keys and values of this array are way are going to be available to us in our template. When we are processing our item_detail.tpl, see how we assign the returned array to the "item" key? This means the item information will be part of the $item variable inside the template.
2). jrCore_db_search_items() takes an array of parameters for it's second argument - you will need to flush that out to suit your needs.
Spend some time testing and playing around with this so you get an idea of how things work - that will allow you to move forward a better pace when you understand how the profile routing works.
Hope this helps!
--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
updated by @brian: 04/15/14 07:56:51AM