LISE : Categories Example -- How do I drill down into Items?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Squire4Hire
Forum Members
Forum Members
Posts: 43
Joined: Wed Dec 09, 2015 11:16 pm

LISE : Categories Example -- How do I drill down into Items?

Post by Squire4Hire »

This is the example template provided in the LISE Categories Template:

Code: Select all

<!-- categories -->
<ul>
{foreach from=$categories item=category}
	<li class="category-{$category->alias}">
		<a class="category-name" href="{$category->url}">{$category->name} ({$category->items|count})</a>
			{if !empty($category->description)}
			<div class="category-description">
				{eval var=$category->description}
			</div>
			{/if}
	</li>
{/foreach}
<ul>
<!-- categories //-->
Is there somewhere that explains the syntax on how to drill down into the items to fetch the data that applies to each of the Categories?

Using {get_template_vars} provides something that looks like this:

Code: Select all

$SCRIPT_NAME (string) = /index.php
$app_name (string) = callable
$sitename (string) = mywebsite
$content_obj (object of type: Content) = {}
$content_id (string) = 27
$page_id (integer) = 27
$page_alias (string) = downloads
$lang (string) = en_US
$encoding (string) = utf-8
$content (string) = 
$current_category (object of type: LISECategory) = {
   .category_id (string) = 1
   .alias (string) = cat_specs
   .name (string) = Equipment Specs
   .description (string) = 

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque rutrum pellentesque imperdiet. Nulla lacinia iaculis nulla non pulvinar. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut eu risus enim, ut pulvinar lectus. Sed hendrerit nibh metus.

   .active (string) = 1
   .position (string) = 1
   .parent_id (string) = -1
   .hierarchy (string) = 00001
   .id_hierarchy (string) = 1
   .hierarchy_path (string) = cat_specs
   .create_date (string) = 2016-10-24 19:48:18
   .modified_date (string) = 2016-10-24 21:54:17
   .key1 (NULL) = 
   .key2 (NULL) = 
   .key3 (NULL) = 
   ->items (array) = [
      .0 (string) = 1
      .1 (string) = 2
   ]
   ->children (array) = [
   ]
   .depth (integer) = 1
   .prevdepth (integer) = 1
   .url (string) = http://mywebsite/index.php/documents/cat_specs/1/27
   .index (integer) = 0
   .menutext (string) = Equipment Specs
   .parent (boolean) = 
   .current (boolean) = 
}
$smarty (NULL) = 
$actionid (string) = mb38af
$actionparams (array) = [
   .action (string) = default
   .module (string) = LISEDocuments
]
$returnid (string) = 27
$actionmodule (string) = LISEDocuments
$mod (object of type: LISEDocuments) = {
   .prefix (string) = documents
   .use_hints (NULL) = 
}
$categories (array) = [
   [0] (object of type: LISECategory) = {
      .category_id (string) = 1
      .alias (string) = cat_specs
      .name (string) = Equipment Specs
      .description (string) = 

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque rutrum pellentesque imperdiet. Nulla lacinia iaculis nulla non pulvinar. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut eu risus enim, ut pulvinar lectus. Sed hendrerit nibh metus.

      .active (string) = 1
      .position (string) = 1
      .parent_id (string) = -1
      .hierarchy (string) = 00001
      .id_hierarchy (string) = 1
      .hierarchy_path (string) = cat_specs
      .create_date (string) = 2016-10-24 19:48:18
      .modified_date (string) = 2016-10-24 21:54:17
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->items (array) = [
         .0 (string) = 1
         .1 (string) = 2
      ]
      ->children (array) = [
      ]
      .depth (integer) = 1
      .prevdepth (integer) = 1
      .url (string) = http://mywebsite/index.php/documents/cat_specs/1/27
      .index (integer) = 0
      .menutext (string) = Equipment Specs
      .parent (boolean) = 
      .current (boolean) = 
   }
   [1] (object of type: LISEItem) = {
      .item_id (string) = 1
      .alias (string) = test-document-1
      .title (string) = Test Document 1
      .url (string) = http://mywebsite/index.php/documents/cat_specs/1/test-document-1/27
      .position (string) = 5
      .active (string) = 1
      .create_time (string) = 2016-10-12 07:26:42
      .modified_time (string) = 2016-10-24 19:49:26
      .start_time (NULL) = 
      .end_time (NULL) = 
      .owner (string) = 2
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->fielddefs (object of type: LISEFielddefArray) = {      }
      .depth (integer) = 2
      .prevdepth (integer) = 1
      .index (integer) = 1
      .menutext (string) = Test Document 1
      .parent (boolean) = 
      .current (boolean) = 
   }
   [2] (object of type: LISEItem) = {
      .item_id (string) = 2
      .alias (string) = test-document-2
      .title (string) = Test Document 2
      .url (string) = http://mywebsite/index.php/documents/cat_specs/1/test-document-2/27
      .position (string) = 6
      .active (string) = 1
      .create_time (string) = 2016-10-12 07:31:07
      .modified_time (string) = 2016-10-24 19:49:35
      .start_time (NULL) = 
      .end_time (NULL) = 
      .owner (string) = 2
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->fielddefs (object of type: LISEFielddefArray) = {      }
      .depth (integer) = 2
      .prevdepth (integer) = 2
      .index (integer) = 2
      .menutext (string) = Test Document 2
      .parent (boolean) = 
      .current (boolean) = 
   }
   [3] (object of type: LISECategory) = {
      .category_id (string) = 2
      .alias (string) = cat_corporate
      .name (string) = Corporate Documents
      .description (string) = 

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque rutrum pellentesque imperdiet. Nulla lacinia iaculis nulla non pulvinar. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut eu risus enim, ut pulvinar lectus. Sed hendrerit nibh metus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque rutrum pellentesque imperdiet. Nulla lacinia iaculis nulla non pulvinar. Sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut eu risus enim, ut pulvinar lectus. Sed hendrerit nibh metus. 

      .active (string) = 1
      .position (string) = 2
      .parent_id (string) = -1
      .hierarchy (string) = 00002
      .id_hierarchy (string) = 2
      .hierarchy_path (string) = cat_corporate
      .create_date (string) = 2016-10-24 19:49:09
      .modified_date (string) = 2016-10-24 21:54:25
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->items (array) = [
         .0 (string) = 3
         .1 (string) = 4
         .2 (string) = 5
         .3 (string) = 6
         .4 (string) = 7
      ]
      ->children (array) = [
      ]
      .depth (integer) = 1
      .prevdepth (integer) = 2
      .url (string) = http://mywebsite/index.php/documents/cat_corporate/2/27
      .index (integer) = 3
      .menutext (string) = Corporate Documents
      .parent (boolean) = 
      .current (boolean) = 
   }
   [4] (object of type: LISEItem) = {
      .item_id (string) = 3
      .alias (string) = corporate-brochure
      .title (string) = Corporate Brochure
      .url (string) = http://mywebsite/index.php/documents/cat_corporate/2/corporate-brochure/27
      .position (string) = 0
      .active (string) = 1
      .create_time (string) = 2016-10-12 07:35:06
      .modified_time (string) = 2016-10-24 19:52:17
      .start_time (NULL) = 
      .end_time (NULL) = 
      .owner (string) = 2
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->fielddefs (object of type: LISEFielddefArray) = {      }
      .depth (integer) = 2
      .prevdepth (integer) = 1
      .index (integer) = 4
      .menutext (string) = Corporate Brochure
      .parent (boolean) = 
      .current (boolean) = 
   }
   [5] (object of type: LISEItem) = {
      .item_id (string) = 4
      .alias (string) = the-way
      .title (string) = The Way
      .url (string) = http:///index.php/documents/cat_corporate/2/the-way/27
      .position (string) = 1
      .active (string) = 1
      .create_time (string) = 2016-10-12 07:36:09
      .modified_time (string) = 2016-10-24 19:52:53
      .start_time (NULL) = 
      .end_time (NULL) = 
      .owner (string) = 2
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->fielddefs (object of type: LISEFielddefArray) = {      }
      .depth (integer) = 2
      .prevdepth (integer) = 2
      .index (integer) = 5
      .menutext (string) =
      .parent (boolean) = 
      .current (boolean) = 
   }
   [6] (object of type: LISEItem) = {
      .item_id (string) = 5
      .alias (string) = mission-statement
      .title (string) = Mission Statement
      .url (string) = http://mywebsite/index.php/documents/cat_corporate/2/mission-statement/27
      .position (string) = 2
      .active (string) = 1
      .create_time (string) = 2016-10-12 07:37:20
      .modified_time (string) = 2016-10-24 19:51:38
      .start_time (NULL) = 
      .end_time (NULL) = 
      .owner (string) = 2
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->fielddefs (object of type: LISEFielddefArray) = {      }
      .depth (integer) = 2
      .prevdepth (integer) = 2
      .index (integer) = 6
      .menutext (string) = Mission Statement
      .parent (boolean) = 
      .current (boolean) = 
   }
   [7] (object of type: LISEItem) = {
      .item_id (string) = 6
      .alias (string) = policy-statement
      .title (string) = Policy Statement
      .url (string) = http://mywebsite/index.php/documents/cat_corporate/2/policy-statement/27
      .position (string) = 3
      .active (string) = 1
      .create_time (string) = 2016-10-12 07:38:21
      .modified_time (string) = 2016-10-24 19:52:32
      .start_time (NULL) = 
      .end_time (NULL) = 
      .owner (string) = 2
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->fielddefs (object of type: LISEFielddefArray) = {      }
      .depth (integer) = 2
      .prevdepth (integer) = 2
      .index (integer) = 7
      .menutext (string) = Policy Statement
      .parent (boolean) = 
      .current (boolean) = 
   }
   [8] (object of type: LISEItem) = {
      .item_id (string) = 7
      .alias (string) = management-system
      .title (string) = Management System
      .url (string) = http://mywebsite/index.php/documents/cat_corporate/2/management-system/27
      .position (string) = 4
      .active (string) = 1
      .create_time (string) = 2016-10-12 07:39:34
      .modified_time (string) = 2016-10-24 19:52:42
      .start_time (NULL) = 
      .end_time (NULL) = 
      .owner (string) = 2
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->fielddefs (object of type: LISEFielddefArray) = {      }
      .depth (integer) = 2
      .prevdepth (integer) = 2
      .index (integer) = 8
      .menutext (string) = Management System
      .parent (boolean) = 
      .current (boolean) = 
   }
   [9] (object of type: LISECategory) = {
      .category_id (string) = 3
      .alias (string) = cat_other
      .name (string) = Other
      .description (string) = 

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque rutrum pellentesque imperdiet. Nulla lacinia iaculis nulla non pulvinar. Sociis natoque penatibus et magnis dis parturient montes.

      .active (string) = 1
      .position (string) = 3
      .parent_id (string) = -1
      .hierarchy (string) = 00003
      .id_hierarchy (string) = 3
      .hierarchy_path (string) = cat_other
      .create_date (string) = 2016-10-24 21:12:55
      .modified_date (string) = 2016-10-24 21:54:35
      .key1 (NULL) = 
      .key2 (NULL) = 
      .key3 (NULL) = 
      ->items (array) = [
      ]
      ->children (array) = [
      ]
      .depth (integer) = 1
      .prevdepth (integer) = 2
      .url (string) = http://mywebsite/index.php/documents/cat_other/3/27
      .index (integer) = 9
      .menutext (string) = Other
      .parent (boolean) = 
      .current (boolean) = 
   }
]
How would I reference the LISEItem objects that pertain to their respective LISECategory objects inside the $categories variable?

Thanks.

Edit:

This gets me the item ID but I cannot figure out how to get the rest of the item data - like name, alias, description, etc.

Code: Select all

{foreach from=$categories item=category}
		{foreach $category->items item=item}			
				{$item}
		{/foreach}
{/foreach}

What am I missing?


Edit #2:

I've modified it a bit to look like this:

Code: Select all

{foreach from=$categories item=category}
			{foreach from=$category item=item}			
				{$item.type}
			{/foreach}
{/foreach}
But this returns garbage: 1 c E < 1 1 - 0 1 c 2 2 h E

If I change it to just {$item} instead of {$item.type} I get:

Code: Select all

1 1 -1 00001 1 cat_specs 2016-10-24 19:48:18 2016-10-24 21:54:17 Array Array 1 1 http://mywebsite/index.php/documents/cat_specs/1/27 0 Equipment Specs 
This starts to look better... but it still doesn't get me the data Im really after. This data is the resulting values of the items inside the Category object - not the Items objects that I would expect.


Edit #3

If I change it to reflect more of what smarty.net suggests in respect to drilling into arrays, I get a similar garbage output that only references the category elements - not the items.

Code: Select all

			{foreach from=$category item=item key=key}		
				{foreach from=$item item=this key=that}	
					{$this} : {$that}
				{/foreach}
			{/foreach}
But now I'm just throwing darts.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: LISE : Categories Example -- How do I drill down into It

Post by velden »

It's all in the help actually, just bring it all together:
Parameters

(optional) action="default" - Override the default action. Possible values are:
"default" - displays the summary view.
"detail" - displays a specified entry in detail mode.
"search" - displays the search form. Optional parameters that affect to this action only: filter.
"category" - displays the categories. Optional parameters that affect to this action only: show_items, collapse, number_of_levels.
"archive" - displays the archives.
(optional) show_items="false" - Applies only to action: category. Append items to category tree.
Additionaly:
{LISELoader}
What does this do?

This plugin allows you to load LISE item and category object by certain criteria, anywhere in the system.
How do I use it?

Simply insert this tag into your page or template:

{LISELoader item='item' identifier='alias' instance='LISEInstance' value='myalias' assign='tmp'}



Following line will load item object from instance 'LISEInstance' by alias 'myalias' and assign it to variable $tmp.
After this you can use it in similar way, just like in regular LISE templates:

{$tmp->title}



If multiple items are being loaded, this function returns array of objects, else it returns single item/category object
What parameters does it take?

(required) instance - Name of instance that holds items. (If used inside LISE templates, this parameter is optional)
(required) value - Comma separated list of identifier values: 'alias1,alias2,alias3' or '1,2,3'
(optional) item="item" - Wanted item type, either: item/category
(optional) identifier="item_id/category_id" - Wanted identifier, one of following: item_id, category_id, alias
(optional) force_array="false" - Force output value as array
Squire4Hire
Forum Members
Forum Members
Posts: 43
Joined: Wed Dec 09, 2015 11:16 pm

Re: LISE : Categories Example -- How do I drill down into It

Post by Squire4Hire »

Velden,

I've read through the help section, but thank you for reposting it verbatim here. Unfortunately the help section does not help me to understand how to implement these parameters in a useful way.

Simply adding the show_items="true" parameter does not explain how to target any of the items inside the Categories Template. It also doesn't explain how to group the items by their respective category. All it does is ensure that the items are loaded into the template.

So yes, as I showed in my original post, I can see that all the items are there and that they are being loaded, but that isn't my question. My question is how to target those items based on the category.

If I'm running a {foreach from=$categories item=category} I can see the list of items and categories but, through all my trials, I cannot seem to figure out how to get the items inside each of the categories.

I'm looking for some kind of syntax example that will help me expose the items that belong to each category.
(optional) show_items="false" - Applies only to action: category. Append items to category tree.
This is great. But how do I display the items in the category tree?

I would like to figure out a way to present the data like this:

Category 1
- Item 1
- Item 2
- Item 3

Category 2
- Item 4
- Item 5

The following example does not work as it returns a garbage string (1 c E < 1 1 - 0 1 c 2 2 h E ):

Code: Select all

{foreach from=$categories item=category}
    {foreach from=$category item=item}
        {$item.title}
    {/foreach}
{/foreach}
Substituting {$item.title} with {$item->title} returns nothing.

Is there a working example somewhere of how to do this? or perhaps some kind of help in explaining how to extract these array objects based on the CMSMS structure using the smarty syntax? or even a suggestion on what I'm doing wrong in the provided examples I've posted above?

Thanks.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: LISE : Categories Example -- How do I drill down into It

Post by Jo Morg »

You really need to understand a bit more how Smarty works...

Code: Select all

{foreach from=$categories item=category}
{****}
{/foreach}
The above code will iterate through each category object in a loop. It just happens that $categories is an array of objects instead of being an array of arrays. The only way to tell what is available as the item variable on each case (besides module documentation and template examples, of course) is to use print_r to inspect what is inside the var:

Code: Select all

{foreach from=$categories item=category}
{$category|print_r:1}
{/foreach}
If it is an array you can use the dot syntax to access it's members like {$foo.bar} or the alternative PHP like syntax {$foo[bar]}, if its an object then you'll need to use the object syntax: {$foo->bar}
Most of the modules use pretty much one or the other.
http://www.smarty.net/docs/en/language. ... iables.tpl
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Squire4Hire
Forum Members
Forum Members
Posts: 43
Joined: Wed Dec 09, 2015 11:16 pm

Re: LISE : Categories Example -- How do I drill down into It

Post by Squire4Hire »

Jo Morg,

I know you're trying to teach me how to fish, but I still don't understand this.

With LISE, it appears to me that the Categories and Items are returned in the same array of objects. I still don't understand how to distinguish between the two. Is there at least a way to get the Type of Object from the array so I can write logic to handle the object properties? There is not [type] or [object_type] variable that I can access. There is simply a LISECategory Object (...) and LISEItem Object(...) within the same array.

I'm really trying to find answers through the Smarty webpage but that's like trying to figure out how to write a VBA macro by reading about Visual Basic. They may be similar in origin but they aren't the same in execution.

I understand that this is likely an easy, mindless task for you, but it would help me immensely if you could give me a piece of code that I could look at, learn from, and to begin to understand how this is meant to work. Throwing a man a fishing pole and a handful of hooks doesn't help him catch a fish.

Yes, I understand that I can look at the variables inside the template. I understand that I can use those variables in different ways. But I do not understand how I can separate or group the Categories from the Items based on the way they are organized in the variable structure.
Squire4Hire
Forum Members
Forum Members
Posts: 43
Joined: Wed Dec 09, 2015 11:16 pm

Re: LISE : Categories Example -- How do I drill down into It

Post by Squire4Hire »

To anyone else out there who may be looking for some help on something like this - here's an actual example of something that should get you started.

By placing this in a LISE Category Template, you can get a separation of the Categories and the Items that apply.

Code: Select all

	{foreach from=$categories item=category}
		{if isset($category->category_id) && $category->items|count > 0}
			{$category->name} </br>
				{foreach from=$category->items item=item}
					{LISELoader item='item' identifier='item_id' instance='LISEDocuments' value={$item.value} assign='tmp'}
					{$tmp->title}
				{/foreach} </br>
		{/if}
	{/foreach}
Locked

Return to “Modules/Add-Ons”