1
spmccain
Edit News Template with using smarty variables
  • 2005/3/24 0:34

  • spmccain

  • Just popping in

  • Posts: 1

  • Since: 2005/3/24


i am having problems understanding totally how smarty works, but I have read the crash course at smarty's site. what I am trying to do is make a block that shows the News topics, currently there is a combobox/form based menu for topics. I want each topic to be printed out and clickable, Like the main menu is. So I started editing the news_block_topics.html template which currently has:

<div style="text-align: center;"><form name="newstopicform" action="<{$xoops_url}>/modules/news/index.php" method="get"><{$block.selectbox}></form></div>



from looking at other blocks I know what types of syntax I will need to use like a "foreach" statement for each topic in the news. Kinda like:

<ul>
  <{foreach 
item=news from=$block.stories}>
    <
li><a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>"><{$news.title}></a> (<{$news.hits}>)</li>
  <{/foreach}>
</
ul>



however, even when I copy this code into the news_block_topics.html file and run it, it doesn't work.

My confusion is mostl with accessing variables, I don't know what is accessible and also how a statement like
{foreach item=news from=$block.stories}
works. I need, general confusion for me, but I am trying to learn by getting this block working.

thanks,
Shawn

2
-DJNZ-
Re: Edit News Template with using smarty variables
  • 2005/3/25 21:27

  • -DJNZ-

  • Just popping in

  • Posts: 30

  • Since: 2005/1/11


You have worked out how Smarty works, but you need to understand how XOOPS works too. I am afraid that the answer is not simple, but here goes...

An XOOPS block is defined in its module's xoops_version.php file. The block that uses the template you are modifying is defined like this:
$modversion['blocks'][1]['file'] = "news_topics.php";
$modversion['blocks'][1]['name'] = _MI_NEWS_BNAME1;
$modversion['blocks'][1]['description'] = "Shows news topics";
$modversion['blocks'][1]['show_func'] = "b_news_topics_show";
$modversion['blocks'][1]['template'] = 'news_block_topics.html';

When XOOPS has to display the block, it uses the above definition to include the file modules/news/blocks/news_topics.php, call the function b_news_topics_show() and fetch the template news_block_topics.html.

This means that in the template you are modifying, the smarty $block variable is set up by the code in the function b_news_topics_show() in the file news_topics.php. If you want to access different data (like the stories data you have copied from news_block_top.html) you have to make sure that this data is loaded into smarty by your PHP code. Again using xoops_version.php, you can see that the code you need is in news_top.php.

I hope this is enough to get you started...

Login

Who's Online

114 user(s) are online (78 user(s) are browsing Support Forums)


Members: 0


Guests: 114


more...

Donat-O-Meter

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

Latest GitHub Commits