Skip to main content

How to suppress blank address line 2

14 years 1 week ago #72471 by mkj101us
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.

14 years 1 week ago #72675 by Xavier
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:
Code:
$html=str_replace('{'.$fieldname.'}',$this->fieldsClass->show($field,$address->$fieldname),$html);
By:
Code:
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.

14 years 6 days ago #73244 by mkj101us
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.

14 years 6 days ago #73317 by Xavier
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.

14 years 6 days ago #73354 by mkj101us
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.

14 years 6 days ago #73376 by Xavier
You address_template should be like that:
Code:
{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:
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.

14 years 4 days ago #73630 by mkj101us
Thanks Xavier. That will work.

-Mike

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

Time to create page: 0.086 seconds
Powered by Kunena Forum