We help IT Professionals succeed at work.

Border and Box Size Limit

Starquest321
Starquest321 asked
on
I need to do two things: First I want to create a border around the Agent Name...Second I would like to limit the size of the full description box (                  {$listing_full_desc[var]}<br ). How can I do that?
<tr style="background: none;">
              <td height="50" style="background: none; border: none;"><a href="site_search.php?listing_agent={$listing_member[var]}">{$listing_username[var]}</a></td>
              <td height="50" style="background: none; border: none;">{$listing_phone[var]}</td>
          </tr>
        </table>	
        <div class="discounted-item widthNmargin" align="right">			
			<a href="{$listing_url[var]}"><strong class="resultHeading">{$listing_title[var]}</strong></a><br />			
			{$listing_full_desc[var]}<br />                  
			<a href="{$listing_url[var]}" class="morebtn"><img src="images/button/more.gif" alt="" /></a>		  
		 </div>
      </div>
      <div class="bBot{$listing_bg[var]}"><img src="images/c3{$listing_bg[var]}.jpg" alt="" align="left" /><img src="images/c4{$listing_bg[var]}.jpg" alt="" align="right" /></div>
    </div>

Open in new window

Comment
Watch Question

Commented:
For the border:

<td height="50" style="background: none; border: 1px solid black;"><a href="site_search.php?listing_agent={$listing_member[var]}">{$listing_username[var]}</a></td>

Commented:
Hi,
I am attaching the code for the complete page. Please find it below.

A briefing about what I have done:
1. The border is controlled via css
2. The height of the box in which $listing_full_desc[var] appears i.e ize of the full description box is also controlled via css.
3. There is a function called limited_text that controls how much text you want to show in the box. Say, $listing_full_desc[var] has content of 100 characters for one post and 2000 characters for other post, in that case, the container box for 2000 character box will expand in height. To restrict that, we are using the function called "limited_text". All you have to do is tell it how many characters you want to accommodate as a standard value and that's it. So if you want, you can show only 50 characters. The rest of the characters will not be shown and will be replaced with ... (3 dots). That's how you can control the text from PHP.

All the above 3 put together should be able to to meet your requirements. In case of any questions, let me know and I will try to help you out further.

Thanks.
<?php 
function limited_text($max_len, $str)
{
	if(!$max_len)
	$max_len = 12; // defult max length of characters including blank spaces
	
	if (strlen($str) > $max_len)
		{
			echo substr("$str", 0, $max_len)."..."; // your portion of text with traling dots "..."
		}
	else
	echo $str;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.agent_border {
	border: 2px solid #06F;
}
.discounted-item {
	height: 100px;
	width: 100%;
}
</style>
</head>

<body>
<table>
<tr style="background: none;">
              <td height="50" style="background: none; border: none;"><a href="site_search.php?listing_agent={$listing_member[var]}" class="agent_border">{$listing_username[var]}</a></td>
              <td height="50" style="background: none; border: none;">{$listing_phone[var]}</td>
          </tr>
        </table>	
        <div class="discounted-item widthNmargin" align="right">			
			<a href="{$listing_url[var]}"><strong class="resultHeading">{$listing_title[var]}</strong></a><br />			
			{limited_text(200, $listing_full_desc[var])}<br />                  
			<a href="{$listing_url[var]}" class="morebtn"><img src="images/button/more.gif" alt="" /></a>		  
		 </div>
      </div>
      <div class="bBot{$listing_bg[var]}"><img src="images/c3{$listing_bg[var]}.jpg" alt="" align="left" /><img src="images/c4{$listing_bg[var]}.jpg" alt="" align="right" /></div>
    </div>
    
</body>
</html>

Open in new window

Author

Commented:

Fatal error: Smarty error: [in site_search.html line 379]: syntax error: unrecognized tag: limited_text(200,{$listing_full_desc[var]) (Smarty_Compiler.class.php, line 439) in /home/israeli1/public_html/libs/Smarty.class.php on line 1095

I get the following when I put in what you said...:(

Author

Commented:
Maybe it should be something from the site search.php that I need to modify and not from the html side since I am using smarty?
Commented:
I am not too acquainted with Smarty as of this moment, but if you know how to apply a function in smarty, then you should apply  limited_text(200, **your description**) function to it. You will need to replace **your description** with the actual content that you want to limit.

Do the following checks:
1. Can you check how to apply a function in Smarty? It should not be too different from what you do in PHP.
2. Did you remember to include the function that I have given you? (i.e. function limited_text($max_len, $str) ...). This is at the top of the script. So make sure that you include them with other functions in smarty.
3. If you are unable to find anything, then try erase the previous code and copy-paste the code below.

Try that out and let me know.
<?php 
function limited_text($max_len, $str)
{
	if(!$max_len)
	$max_len = 12; // defult max length of characters including blank spaces
	
	if (strlen($str) > $max_len)
		{
			echo substr("$str", 0, $max_len)."..."; // your portion of text with traling dots "..."
		}
	else
	echo $str;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.agent_border {
	border: 2px solid #06F;
}
.discounted-item {
	height: 100px;
	width: 100%;
}
</style>
</head>

<body>
<table>
<tr style="background: none;">
              <td height="50" style="background: none; border: none;"><a href="site_search.php?listing_agent={$listing_member[var]}" class="agent_border">{$listing_username[var]}</a></td>
              <td height="50" style="background: none; border: none;">{$listing_phone[var]}</td>
          </tr>
        </table>	
        <div class="discounted-item widthNmargin" align="right">			
			<a href="{$listing_url[var]}"><strong class="resultHeading">{$listing_title[var]}</strong></a><br />			
			limited_text(200, {$listing_title[var]})<br />                  
			<a href="{$listing_url[var]}" class="morebtn"><img src="images/button/more.gif" alt="" /></a>		  
		 </div>
      </div>
      <div class="bBot{$listing_bg[var]}"><img src="images/c3{$listing_bg[var]}.jpg" alt="" align="left" /><img src="images/c4{$listing_bg[var]}.jpg" alt="" align="right" /></div>
    </div>
    
</body>
</html>

Open in new window