Page 1 of 1

How to access category alias with ListIt2Loader?

Posted: Thu Dec 26, 2013 7:23 am
by Simon66
I'm using ListIt2 and ListIt2Loader to pull in the categories, but I need to output the alias instead of the name.

This is the code I'm using:

Code: Select all

{ListIt2Loader item='category' force_array=1 instance='ListIt2Portfolio' value=$item->categories assign='cats'}
<li class="item" data-id="id-{$smarty.foreach.count.iteration}" data-type="{$cats|implode:','}">
The $cats array outputs the names of the associated categories but I can't output the alias.

Using |print_r to view the contents of the $cats array I get this:

Code: Select all

Array
(
    [4] => ListIt2Category Object
        (
            [category_id] => 4
            [alias] => style-guides
            [name] => Style Guides
            [description] => 
            [active] => 1
            [position] => 1
            [parent_id] => -1
            [hierarchy] => 00001 etc.
Any ideas on accessing the alias?

Re: How to access category alias with ListIt2Loader?

Posted: Thu Dec 26, 2013 11:24 am
by Stikki
{foreach name=$cats item='one_cat'}
{$one_cat->alias}
{/foreach}

Re: How to access category alias with ListIt2Loader?

Posted: Thu Dec 26, 2013 11:36 pm
by Simon66
Thanks Stikki! ;D

Re: How to access category alias with ListIt2Loader?

Posted: Thu Apr 03, 2014 3:21 pm
by JM6891
Thank you - also helped me out too!

Re: How to access category alias with ListIt2Loader?

Posted: Tue May 20, 2014 2:40 pm
by noosphere
Stikki wrote::-D
Hello Stikki and all others on the forum!
I'm trying to get the ListIt2 categories to populate my Advanced Content dropdown in the backend to select different playlists based on the ListIt2 categories.

Here's what I got so far:

1. my udt named "get_cat"

Code: Select all

$data = "{ListIt2Loader item='category' force_array=1 instance='ListIt2Courses' value=$item->categories assign='cats'}";
$mycats = implode(",", $data);
echo $mycats;
2. my page template calling the udt

Code: Select all

{content block="playlist" label="Select Playlist" block_type="dropdown" items=":::get_cat:::" assign="playlist" editor_groups="Admin,Editor" smarty="true"}
But I'm not getting any data back.

3. also tried with different options

Code: Select all

$data = "{ListIt2Courses action='category'}";
//which returns my categories separated by |
//echo $smarty->display('eval:'.$smarty_data);
// ECHO in frontend displays the categories correctly
$smarty->display('eval:'.$data);
// but in both cases the backend page is blank !

Do you or anybody else out here have any suggestion/hint for me please ?

Thank you in advance and thank you for your great module !
#Ed

Re: How to access category alias with ListIt2Loader?

Posted: Tue May 20, 2014 3:19 pm
by velden
Some considerations:

1. you can't use Smarty tags in UDT
2. echo $data will output $data, you'd need return $data but it will not work because of 1.
3. what's that ':::get_cat:::' syntax? I don't know it.
4. I don't know if you can use this approach in backend/admin at all (calling listit2loader and do something with the results in the next {content} block.)

Re: How to access category alias with ListIt2Loader?

Posted: Tue May 20, 2014 5:31 pm
by Stikki
Like Velden said don't use Smarty tags inside PHP.

Use Module API functions and ListIt API functions to gain what you want. All public methods are in main module class (ListIt2.module.php).

Reason why i don't provide code snippet is because it's custom coding your doing and wish no copy-paste guys to get their hands into it.