• So I am trying to loop through items and display comma separated each time excluding the last item in the list. Relevant portion of code is as below. Is there an equivalent of [apr field=”” glue=””] that can be used inside a loop?

    [apr_populate field="Coach" relatedTo="Coaches"]
    [apr_loop]
    Coaches: [apr_loop1 field="Coach"]<a href="/coaches-list/{{Slug}}">{{Name}}, </a>[/apr_loop1]
    [/apr_loop]
    • This topic was modified 5 years, 10 months ago by webfliccy.
    • This topic was modified 5 years, 10 months ago by webfliccy.
    • This topic was modified 5 years, 10 months ago by webfliccy.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Pat K

    (@blackcapdesign)

    Good question! I haven’t found an Airpress method to achieve this, but it is possible using a CSS3 pseudo-element. If you wrap {{Name}} in a set of inline tags (such as span, i or em) it’s possible to add the comma as a pseudo-element via CSS like so:

    div.comma-separated-list span:after {
    	content: ', ';
    }
    div.comma-separated-list i:last-of-type:after {
    	content: '';
    }

    It would be awesome if there were a way to achieve this with Airpress (seems simple enough) but this is a workaround which I’ve used successfully. Hope this helps…
    pk

    Thread Starter webfliccy

    (@webfliccy)

    Thanks Pat K for thinking outside the box. I come from a front-end coding background so I like the use of css.

    A related question is – can you tell if an [apr] loop is empty? For example I would like headings for different sections but only to display these when the field is not empty.

    Pat K

    (@blackcapdesign)

    Another good question! I know exactly what you mean and have run into this myself. There is no Airpress method that I am aware of (I’m sure Chester will chime in if there is). So headings that are followed by empty fields are just that: headings followed by empty fields. I seem to remember trying to use a jQuery filter to address this (removing these headings dynamically) without success. If you find a method to do this, please post your solution!
    pk

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using glue within [apr_loop]’ is closed to new replies.