Classes for Quick Links and Top Menu Items

I’m currently trying to customise CS Cart so that we can specify classes for each menu item we make, allowing us to make multi coloured links and tabs in our menus.



So far i have figured out that under [cscart]/schemas/static_data/schema.php - i can adjust the form for Quick links, the original code;

'N' => array( // quick links
'param' => 'url',
'descr' => 'link_text',
'add_title' => 'add_new_items',
'add_button' => 'add_item',
'edit_title' => 'editing_item',
'mainbox_title' => 'quick_links',
'has_localization' => true,
),


new code;

'N' => array( // quick links
'param' => 'url',
'descr' => 'link_text',
'add_title' => 'add_new_items',
'add_button' => 'add_item',
'edit_title' => 'editing_item',
'additional_params' => array(
array(
'title' => 'class',
'type' => 'input',
'name' => 'param_2'
),
),
'mainbox_title' => 'quick_links',
'has_localization' => true,
),




This adds another textbox that users can enter detail into and it does save into the database. I tried to update the template to use the new value;

```php

{hook name=“index:bottom_links”}


{foreach from=$quick_links item="link"}
{$link.descr}
{$link|@print_r}
{/foreach}


{/hook}
```

the code doesn't put out any class - and the 'print_r' statment shows that the 'param_2' just isn't passing through. I've gone to "&cc" to clear the cache and deleted all the customer compiled files.

Is there some other cache/compiling i need to clear, or am i missing something? It's a rather simple feature, and it's frustrating that i'm so close, but just can't seem to get the last bit to work, getting the info showing the the template files.

Cheers for the assistance,
Alex

I think it is the template problem





You should try like this



class="{$link.additional_params.param_2}"




You are trying to get the index that is not started



i.e param_2in the $link.



Rather it is in additional_params.



In the end thanks for your Code



Cheers

Perochak

This should help [url]http://forum.cs-cart.com/showthread.php?t=19385[/url]

[quote name=‘Perochak’]I think it is the template problem

You should try like this



class="{$link.additional_params.param_2}"


[/QUOTE]



Hadn’t thought of that one, just gave it a go, unfortunately didn’t work. It just seems as my CSCart is not loading that additional data at all;



The print_r is putting out this structure


Array ( [param_id] => 19 [param] => index.php [descr] => Home ) 1




Just as a quick check i also did a print_r on the top-menu - which by default is already using param_2 and param_3


Array ( [param_id] => 23 [param_2] => index [param_3] => [param_4] => [param_5] => [status] => A [position] => 1 [parent_id] => 0 [id_path] => [item] => Home [href] => index.php [selected] => 1 ) 1




It’s interesting that ‘$m’ there will like out all 5 param, even though only some of them have been set - it makes me wonder if i have missed some code somewhere.


[QUOTE]

In the end thanks for your Code

[/QUOTE]



It’s not working yet! When i have it going i’ll put up instructions for others. It’s fucntionality many open-source frameworks use, so it’s sorely missed! :slight_smile:


[QUOTE]

[url]http://forum.cs-cart.com/showthread.php?t=19385[/url]

[/QUOTE]

This works fine if you want unique identifiers - however in this case because an end user needs to be able to control this, i need to do it via human readable and recyclable classes, so they can re-arrange and change the formatting of tabs/links as they want, without understanding or touching the css.



Thanks for the suggestions so far!



Any other ideas where i might have missed something?

Aha! Found a missing ‘true’!



Adding User Defined Classes to individual Quick Links



In [cscart]/init.php you’ll find this line;


// Get quick links
Registry::register_cache('quick_links', array('static_data'), CACHE_LEVEL_LOCALE);
if (Registry::is_exist('quick_links') == false) {
Registry::set('quick_links', fn_get_static_data_section('N'));
}




This will need to be changed to;


// Get quick links
Registry::register_cache('quick_links', array('static_data'), CACHE_LEVEL_LOCALE);
if (Registry::is_exist('quick_links') == false) {
Registry::set('quick_links', fn_get_static_data_section('N'[b], true[/b]));
}




This will activate collecting extra params on quick links. If you want to do this for the ‘top menu’ then you already have the extra params activated.



Under [cscart]/schemas/static_data/schema.php


'N' => array( // quick links
'param' => 'url',
'descr' => 'link_text',
'add_title' => 'add_new_items',
'add_button' => 'add_item',
'edit_title' => 'editing_item',
'mainbox_title' => 'quick_links',
'has_localization' => true,
),




Change to


'N' => array( // quick links
'param' => 'url',
'descr' => 'link_text',
'add_title' => 'add_new_items',
'add_button' => 'add_item',
'edit_title' => 'editing_item',
[b]'additional_params' => array(
array(
'title' => 'css_class',
'type' => 'input',
'name' => 'param_2'
),
),[/b]
'mainbox_title' => 'quick_links',
'has_localization' => true,
),




In the template you will need to change the lines in bottom.tpl or top_quick_links.tpl etc to

```php

{hook name=“index:bottom_links”}


{foreach from=$quick_links item="link"}
{$link.descr}
{/foreach}


{/hook}
```

The last step, you will need to enter a new entry into the 'language_values' in sql for 'css_class', you could do this with PhpMyAdmin, or somehow execute this sql;
```php
INSERT INTO `cscart`.`cscart_language_values` (
`lang_code` ,
`name` ,
`value`
)
VALUES (
'EN', 'css_class', 'Tab Style'
); ```

Make sure you clear your caches and delete the 'compiled' files in the 'var' file!

[b]To do this for the Top Menu, you only need to update the scheme.php and template files, by including a new entry for param_5[/b], however this is the last entry you can add to the Static Data, so if you wish to include more customizations, you're kinda stuck with that, :(. Template code is much the same, just param_5 instead, :).

I hope this helps you guys out there, thanks for the assist!