Jump to content

Undefined index: name while trying to display category names in a custom module


prak

Recommended Posts

Hello, I am trying to make a module named 'categorieslist' which displays a list of categories on the home page, here is how I got the array of categories in categorieslist.php. I am using Prestashop 1.6.1.8

    public function hookDisplayHome()
    {
      $lang = (int)Context::getContext()->language->id;
      $cats = Category::getCategories($lang);
      $this->context->smarty->assign(
    array(
        'categories_list_name' => Configuration::get('CATEGORIESLIST_NAME'),
        'categories_list_link' => $this->context->link->getModuleLink('categorieslist', 'display'),
        'cats' => $cats
    )
    );
    return $this->display(__FILE__, 'categorieslist.tpl');
    }

here is how I am trying to display the names of the categories in my categorieslist.tpl

<div class="block_content">
		{foreach from=$cats item=cat}
			<div class="cat">
				<a href="" class="catname">
					{$cat.name}
				</a>
				<ul>
			</div>
		{/foreach}
 </div>

 I am getting this error message, "notice: unidentified index: name"

 

How can I solve this issue?

 

 

 

 

Link to comment
Share on other sites

Your PHP code is assuming that the call to Category::getCategories is returning a list of categories.

 

If you put:

 

{debug}

 

in your categorieslist.tpl and refresh the page (having emptied the cache etc) your browser will open a second window containing a dump of all the template variables on the page.

 

This will show whether $cats has any data in it.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...