1
Anonymous
Automatic generation of category-based templates
  • 2004/3/11 23:01

  • Anonymous

  • Posts: 0

  • Since:


Sometimes it would be nice if every category could have it's own different templates. This is a quick and dirty solution. News module is taken as example. Open news/xoops_version.php in an editor and replace this code:

// Templates
$modversion['templates'][1]['file'] = 'news_archive.html';
$modversion['templates'][1]['description'] = '';
$modversion['templates'][2]['file'] = 'news_article.html';
$modversion['templates'][2]['description'] = '';
$modversion['templates'][3]['file'] = 'news_index.html';
$modversion['templates'][3]['description'] = '';
$modversion['templates'][4]['file'] = 'news_item.html';
$modversion['templates'][4]['description'] = '';


with this code:

// Templates
$modversion['templates'][1]['file'] = 'news_archive.html';
$modversion['templates'][1]['description'] = '';
$modversion['templates'][2]['file'] = 'news_article.html';
$modversion['templates'][2]['description'] = '';
$modversion['templates'][3]['file'] = 'news_index.html';
$modversion['templates'][3]['description'] = '';
$modversion['templates'][4]['file'] = 'news_item.html';
$modversion['templates'][4]['description'] = '';
$modversion['templates'][5]['file'] = 'news_article1.html';
$modversion['templates'][5]['description'] = 'Kat-ID 1';

global 
$xoopsDB;
$i 6;

$result $xoopsDB->query("SELECT topic_id FROM
"
.$xoopsDB->prefix("topics")."");

    while (list(
$topic_id) = $xoopsDB->fetchRow($result)) {
$modversion['templates'][$i]['file'] =
'news_article'.$topic_id.'.html';
$modversion['templates'][$i]['description'] = 'Kat-ID '.$topic_id;
$quelle XOOPS_ROOT_PATH.'/modules/news/templates/news_article.html';
$ziel =
XOOPS_ROOT_PATH.'/modules/news/templates/news_article'.$topic_id.'.html';

if (
!
file_exists(XOOPS_ROOT_PATH.'/modules/news/templates/news_article'.$topic_id.'.html')
) {
        
copy($quelle$ziel); 
}
$i++;
}


Open news/article.php in an editor and delete following line:

$xoopsOption['template_main'] = 'news_article.html';


Insert following line before including footer.php:

$xoopsOption['template_main'] = 'news_article'.$article->topicid().'.html';


This it how it works: First you have to create categories in news, then you have to update the module. Then go to the Templates-Manager and generate the new templates. The original news_article.html is the source for the copies, so if you want to spare some time you can change this FILE.

Unfortunately news/templates must be writable.

I think my solution will work for any module working with categories.

Login

Who's Online

212 user(s) are online (140 user(s) are browsing Support Forums)


Members: 0


Guests: 212


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits