Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

List of alphabets (A to Z) with links

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Mon Oct 12, 2009 8:03 am    Post subject: List of alphabets (A to Z) with links Reply with quote

This plugin lists out alphabets from A to Z, each with links, and can help you make better navigator. You can define the link page, index name of the $_GET variable, and define an active alphabet to highlight.

Most of the menus work with css, UL, LI, SPAN an A tags. So, this should a highly reusable plugin for any applications you make.

Code:
<?php
/**
* Prints out A- Z with a link
*/

function smarty_function_a2z($params=array(), &$smarty)
{
   $params['url'] = !empty($params['url'])?$params['url']:'letter.php';
   $params['name'] = !empty($params['name'])?$params['name']:'L'; # $_GET index
   $params['active'] = !empty($params['active'])?$params['active']:'A';
   
   $links = array();
   for($letter = ord('A'); $letter <= ord('Z'); ++$letter)
   {
      $alphabet = chr($letter);
      $active = ($alphabet==$params['active'])?' class="active"':'';
      $links[] = "<li{$active}><span><a href='{$params['url']}?{$params['name']}={$alphabet}'>{$alphabet}</a></span></li>";
   }
   return(implode('', $links));
}
?>

Just, save the above code as function.a2z.php into your plugins directory.

Here are the usage examples:
Code:
<ul>{a2z}</ul>

or,
Code:
<ul class="alphabets">
  {a2z url='begin.php' name='letter' active='C'}
</ul>


The basic css you may use is:
Code:
ul.alphabets
{
}

ul.alphabets li
{
   list-style:none;
   float:left;
   margin-right:5px;
   padding:3px 5px 3px 5px;
   border:1px solid #FFFFFF;
   text-align:center;
}

ul.alphabets li.active, ul.alphabets li:hover
{
   background-color:#990000;
   border:1px solid #FFFF00;
}
ul.alphabets li a
{
   text-decoration:none;
}
ul.alphabets li.active a, ul.alphabets li:hover a
{
   color:#CCCCCC;
}


Parameter url is a link to a page.
Parameter name is the index flag name for $_GET variable.
Parameter active holds an alphabet to highlight. You need css to do this.

Enjoy and please feedback me.
Back to top
View user's profile Send private message Visit poster's website
jothirajan
Smarty Pro


Joined: 06 Feb 2009
Posts: 114
Location: India

PostPosted: Thu Oct 15, 2009 9:37 am    Post subject: Doubt !!! Reply with quote

Dear Bimal,

I have tried this before a month for to encypt my ID. I got the result.

Thats my first PLUGIN in my career. But when i just altered your code like the below

Code:

<ul class="alphabets">
  {a2z url='a2z.php' name='letter' active="{$smarty.request.letter}"}
</ul>


I am getting the output as

* Array ( [url] => a2z.php [name] => letter [active] => {.request.letter ) A
* B
* C
* D
* E
* F
* G
* H
* I
* J
* K
* L
* M
* N
* O
* P
* Q
* R
* S
* T
* U
* V
* W
* X
* Y
* Z
"} O

Think so this is not accepting the {Smarty} tag.

HELP !!!!
Back to top
View user's profile Send private message Send e-mail
jothirajan
Smarty Pro


Joined: 06 Feb 2009
Posts: 114
Location: India

PostPosted: Thu Oct 15, 2009 9:42 am    Post subject: I got it Reply with quote

Yeap !!!!

Thanks for your time.....

I have tried this in php file just like
Code:


$JO_SMARTY->assign("MYLETTER",$_REQUEST['letter']);


and assigned the same in my TPL

Code:

 {a2z url='a2z.php' name='letter' active=$MYLETTER}



BUT WE ARE NOT ABLE TO ASSIGN THE SMARTY TAG THERE IN THE TPL AREA ?. YOUR SUGGESTION PLEASE
Back to top
View user's profile Send private message Send e-mail
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Thu Oct 15, 2009 12:34 pm    Post subject: Your last attempt is good. Reply with quote

$smarty – if not assigned by default, you can choose a different, simple variable like $letter or $ MYLETTER. You may have to enable smarty security, if $smarty is not available, and you want to use it any how.

And you do not need to enquote the variable in the function call. Your last attempt is good.

Also, $letter should contain a single letter between A and Z, in upper case only (just to match for applying active class).

If the problem is due to html LI tags (mutli line output), use the sample css I have given in the example.
Back to top
View user's profile Send private message Visit poster's website
ulmarry
Smarty n00b


Joined: 18 Jan 2013
Posts: 1

PostPosted: Fri Jan 18, 2013 1:22 am    Post subject: Reply with quote

Hi guys.

I'm having some trouble implementing this to my code, the way my code looks. I'm wondering if you have any suggestions to how I can add it without making any fundamental changes to it?

My .php file contains this:
Code:
while($row = mysql_fetch_array($result)) {
  $allItems[] = '<a href="'.MAIN_URL .'/list/'. $row['itemID'] .'/" title="'. $row['itemName'] .'">' . stripslashes($row['itemName']) . '</a>';
}


The .tpl file contains this:
Code:
{html_table loop=$allItems cols=4 table_attr='cellspacing="4" border="0" width="100%"' td_attr='style="width: 230px; padding: 2px 2px; border:none;"'}


Any help would be highly appreciated.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP