[SOLVED] address template

  • Posts: 192
  • Thank you received: 1
12 years 11 months ago #39342

Hi,

i would like to display correct information on my address template and for that i was thinking to test first if data are available, if not, i do not display anything.

for example, if user typed 2 addresses (1 for company, 1 personal), i want firstly to test if 1 address is has a company name, so i was thinking to use the following code:

<?php if($this->address_company){ ?>
    <tr><td>Company:</td><td>{address_company}</td></tr>
  <?php }; ?>

in my address_template view, however in case, client typed 1 address for company (with company name) and 1 address for personal usage... in both case the company name is not displayed.

so what is it wrong ?

thx.
A.


What does not kill you, makes you stronger.
Last edit: 12 years 11 months ago by alain.roger.

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

  • Posts: 83103
  • Thank you received: 13415
  • MODERATOR
12 years 11 months ago #39477

Hi,

That's easy: $this->address_company does not exists.
You cannot access the address information in the address_template views.

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

  • Posts: 192
  • Thank you received: 1
12 years 11 months ago #39582

Ok, so as i have a custom field call "address_entity_type" that is equal to "Person" (in case it's a personal address) or "Company" (in cas it's a business address).
in the address_template view i created a test before to determine which type of address it is.

<?php
$entity = JText::sprintf('%s','{address_entity_type}');
?>

<table class="address_4_rogtek">
  <tr><td>Entity Type: <?php echo $entity; ?></td></tr>
  <tr><td>Matches: <?php echo preg_match("/Company/",$entity,$matches); ?></td></tr>
  <?php if($matches > 0)
    {
  ?>
    <tr><td>Company: {address_company}</td></tr>
    <tr><td>{address_vat}</td></tr>
    <tr><td>{address_trading_chamber_number}</td></tr>
  <?php  }; ?>
  <tr><td>{address_title} {address_firstname} {address_lastname}</td></tr>
  <tr><td>{address_street}</td></tr>
  <tr><td>{address_post_code} {address_city}</td></tr>
  <tr><td>{address_state}</td></tr>
  <tr><td>{address_country}</td></tr>
  <?php echo "<tr><td>".JText::sprintf('TELEPHONE_IN_ADDRESS','{address_telephone}')."</td></tr>";?>
</table>
<?php
  unset($entity);
?>

this code is only for test purpose and for now i get the following results:



What does not kill you, makes you stronger.
Attachments:
Last edit: 12 years 11 months ago by alain.roger.

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

  • Posts: 83103
  • Thank you received: 13415
  • MODERATOR
12 years 11 months ago #39725

As I said, it's not possible to do that.
The PHP file is processed by PHP BEFORE the tags are replaced with the address data.

So preg_match("/Company/",$entity,$matches) will always return 0 because $entity is equal to {address_entity_type} and not the value of the custom field chosen by the user.

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

  • Posts: 192
  • Thank you received: 1
12 years 11 months ago #39747

Hi Nicolas,

i this case i would like to know how do you solve thecurrent situation:

1.user has 2 different addresses (1 for company and 1 for personal usage) with both different custom fields.
2. when addresses are displayed as some fields are empty, there are a suite of <br /> tags which only create a move of next information downward.
If you tell CSS to not display <br />, the complete address is a simple line of all fields concatenated and not readable

Q: how do you cope with that ? Maybe i missed the point but when i display an address, i'm pleased when it's clear and readable, so each field as it's own place and no "blank space" (<br /> tags without field data) which create a downward move as in the attachment.



What does not kill you, makes you stronger.
Attachments:

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

  • Posts: 192
  • Thank you received: 1
12 years 11 months ago #39757

I found how to cope with it.
i paced everything in different <span> tags and in 1 single line to avoid <br />
Now it works as i wanted.


What does not kill you, makes you stronger.

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

  • Posts: 83103
  • Thank you received: 13415
  • MODERATOR
12 years 11 months ago #39880

Yes, that's the best way to do it.

Using conditional PHP in the address template is not possible. We'll add that to the todo list. It's practical to be able to add PHP code directly in it to display or not some things based on others.

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

Time to create page: 0.110 seconds
Powered by Kunena Forum