How to suppress blank address line 2

  • Posts: 12
  • Thank you received: 0
12 years 2 weeks ago #72471

Hello,

I'm trying to modify address / address_template.php to suppress {address_street2} if it is blank. However, I cannot get access to the value of {address_street2} to check its length.

I can tell I do not have the value of {address_street2} by adding this to the template:

<?php
$arr1 = str_split('{address_street2}');
print_r($arr1);
?>

That will print the label, rather than the value:

Array
(
[0] => {
[1] => a
[2] => d
[3] => d
[4] => r
[5] => e
[6] => s
[7] => s
[8] => _
[9] => s
[10] => t
[11] => r
[12] => e
[13] => e
[14] => t
[15] => 2
[16] => }
)

But what I don't understand is why this does print the value of {address_street2}:

<?php
echo 'line 2 is '.'{address_street2}';
?>


Is there a way to check for the existence of a value in {address_street2} and not print that line if there is nothing in it?

Thanks,
-Mike

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
12 years 2 weeks ago #72675

Hi,

To display the address_street2 only if there is something in the address, add the tag "{address_street2}" in the view "address / address_template" and then edit the view "address / listing" and replace the line:

					$html=str_replace('{'.$fieldname.'}',$this->fieldsClass->show($field,$address->$fieldname),$html);
By:
				if($fieldname != 'address_street2' || ($fieldname == 'address_street2' && !empty($fieldname))){
					$html=str_replace('{'.$fieldname.'}',$this->fieldsClass->show($field,$address->$fieldname),$html);
				}

Please Log in or Create an account to join the conversation.

  • Posts: 12
  • Thank you received: 0
12 years 2 weeks ago #73244

Hi Xavier,

I see what you are trying to do, however it seems that the layout in "address / address_template" is overridding what you are doing in "address / listing" and always adding a line for address_street2.

The contents of "address / listing" is:

<?php
/**
* @package HikaShop for Joomla!
* @version 1.6.0
* @author hikashop.com
* @copyright (C) 2010-2012 HIKARI SOFTWARE. All rights reserved.
* @license GNU/GPLv3 www.gnu.org/licenses/gpl-3.0.html
*/
defined('_JEXEC') or die('Restricted access');
?>
{address_company}
{address_title} {address_firstname} {address_lastname}
{address_street}
{address_street2}
{address_post_code} {address_city} {address_country}
{address_state}
<?php echo JText::sprintf('TELEPHONE_IN_ADDRESS','{address_telephone}');?>

Thoughts?

Thanks,
-Mike

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
12 years 2 weeks ago #73317

Hi,

I think that the code given is in the file "address / address_template", if it's in the file "address / listing", delete the customizations by clicking on the dustbin in the listing of the views in HikaShop > Display > Views.
And then edit this view again to make the changes given.

Please Log in or Create an account to join the conversation.

  • Posts: 12
  • Thank you received: 0
12 years 2 weeks ago #73354

I'm sorry, yes that code I supplied is from "address / address_template" & I added your if() statement to "address / listing" -- that scenario is where address_template is always adding a blank line for address_street2.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
12 years 2 weeks ago #73376

You address_template should be like that:

{address_company}
{address_title} {address_firstname} {address_lastname}
{address_street}{address_street2}
{address_post_code} {address_city} {address_state}
{address_country}
<?php echo JText::sprintf('TELEPHONE_IN_ADDRESS','{address_telephone}');?>

And if you want the second address (when filled) at the line, in the listing view replace with the code:
if($fieldname != 'address_street2'){
	$html=str_replace('{'.$fieldname.'}',$this->fieldsClass->show($field,$address->$fieldname),$html);
}elseif($fieldname == 'address_street2' && !empty($fieldname)){
	$html= "<br/>".str_replace('{'.$fieldname.'}',$this->fieldsClass->show($field,$address->$fieldname),$html);
}

Please Log in or Create an account to join the conversation.

  • Posts: 12
  • Thank you received: 0
12 years 2 weeks ago #73630

Thanks Xavier. That will work.

-Mike

Please Log in or Create an account to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum