elivz / VzAddress-Craft

Address fieldtype for the Craft CMS
30 stars 13 forks source link

Possible to wrap each line with `<li>` tags? #9

Closed andregoldstein closed 7 years ago

andregoldstein commented 8 years ago

Hi there, possible feature request, as above, would it be feasible to offer an <li> tag output?

Thanks

elivz commented 8 years ago

Hey Andre,

I will consider this for a future release, but to be honest I'm not entirely sold on it as a core feature. However it is very easy to use your own template for rendering the address in whatever format you want! Just use one of the templates files from vzaddress/templates/_frontend as an example. Save it into your templates folder and then include it wherever you want to render the address, passing in your address field like this:

templates/_partials/address.twig

<ul>
  {% if address.name %}<li>{{ address.name }}</li>{% endif %}
  {% if address.street %}<li>{{ address.street }}</li>{% endif %}
  {% if address.street2 %}<li>{{ address.street2 }}</li>{% endif %}
  <li>
    {% if address.city %}{{ address.city }}, {% endif %}
    {{ address.region }} {{ address.postalCode }}
  </li>
  {% if includeCountry %}<li>{{ address.countryName }}</li>{% endif %}
</ul>

Wherever you want to display an address:

{% include '_partials/address' with { entry.addressField as address} only %}
andregoldstein commented 8 years ago

Thanks very much Eli! I guess the use case is that when creating a design I would tend to use an unordered list to display an address more often than <p> tags with <br> tags.

Thanks for the tip though on the partial!

On 17 February 2016 at 19:50, Eli Van Zoeren notifications@github.com wrote:

Hey Andre,

I will consider this for a future release, but to be honest I'm not entirely sold on it as a core feature. However it is very easy to use your own template for rendering the address in whatever format you want! Just use one of the templates files from vzaddress/templates/_frontend as an example. Save it into your templates folder and then include it wherever you want to render the address, passing in your address field like this: templates/_partials/address.twig

    {% if address.name %}
  • {{ address.name }}
  • {% endif %} {% if address.street %}
  • {{ address.street }}
  • {% endif %} {% if address.street2 %}
  • {{ address.street2 }}
  • {% endif %}
  • {% if address.city %}{{ address.city }}, {% endif %} {{ address.region }} {{ address.postalCode }}
  • {% if includeCountry %}
  • {{ address.countryName }}
  • {% endif %}

Wherever you want to display an address:

{% include '_partials/address' with { entry.addressField as address} only %}

— Reply to this email directly or view it on GitHub https://github.com/elivz/VzAddress-Craft/issues/9#issuecomment-185374063 .

André Goldstein Director, Milktop

http://www.milktop.co.uk http://www.milktop.co.uk @MilktopDesign https://twitter.com/MilktopDesign