• Resolved mazoola

    (@mazoola)


    Chester –

    I’ve been thrashing this one about for a while, now.

    This is still with the Wardrobe base. I have an Outfits table where each record contains a field, Garment, that is a link to multiple records in the Garments table. In turn, each Garment record contains an Images field that is an attachment field containing zero to many images.

    I am currently working on an Outfit display screen driven by a VirtualPost matching a single Outfit record. On this screen, I want to loop through all Garments linked from the Outfit and display per-Garment data. I do this by first populating the related record: [apr_populate field="garment" relatedTo="garments"]. I then call [apr_loop field="garment"]. Within the loop I specify Garment fields using the {{}} syntax; everything works fine.

    If I want, I can also display all images associated with the Garment by means of a nested loop: [apr_loop1 field='images']. Within this second loop, I can access fields from each Garment>images instance, again using {{}} syntax. However, what I cannot seem to do is access only a single Garment image — even though v 1.34 of Airpress is supposed to support [apr field=] within [apr_loop]s.

    If I call [apr field="garment|image|url" single] from inside the loop, if the shortcode is embedded within html — for instance, as in <img style="max-height: 50px;" src="[apr field='garment|image|url' single]"> — the shortcode is replaced by the RECORD_ID of the current Garment. If the shortcode is not embedded within an HTML declaration but is still inside the loop, it simply disappears — that is, is replaced by nothing.

    Outside of the loop, but still after the call to [apr_populate], the shortcode is again replaced by the RECORD_ID if called from within an HTML declaration. However, if called outside of the loop and outside of an HTML declaration, the shortcode [apr field='garment|image|url' single] is replaced by the appropriate URL. (Of course, since that only works outside HTML, it doesn’t do much good.)

    If I call a comparable Outfit-level shortcode outside of the [apr_populate] block, it is replaced by the appropriate URL — both inside and outside of HTML declarations.

    As best I can tell, there is no way to specify ‘single’ while using {{}} syntax.

    I’ve tried to trace through the code to see if I could find something to tweak, but as I’m not using an IDE, trying to follow routine execution using nothing but airpress_debug() statements is slow and painful — especially when I can simply ask the guy who wrote the thing!

    If I can provide any additional info, don’t hesitate to ask.

    Thanks,
    maz

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mazoola

    (@mazoola)

    Chester –

    After far too much banging of my head against the wall, I hit upon the boneheadedly simple idea of extracting the first image’s URL and storing it as an Airtable field. Unfortunately, I don’t seem to be able to access either thumbnail URL through Airtable, so very large images can slow down initial page loads — but I can now get back to the business of actually building the app.

    I’d still like to understand better the combined Airpress/WprdPress loop, as the one thing I managed to learn after hours of tracing through the code was I’d been looking in entirely the wrong place: The shortcodes referencing the images were being stripped or [incorrectly] replaced well before my window of visibility opened.

    Unfortunately, I’m also nearing the end of what I can accomplish using only shortcodes — and, so far, my experience with using both shortcodes and PHP routines on the same resource hasn’t been the best. The next couple of weeks, I’ll be moving within the city, but once that’s done expect me to pipe up even more frequently with questions

    Plugin Author Chester McLaughlin

    (@chetmac)

    Just released 1.1.37 with some pretty significant improvements to the apr_loop and apr shortcodes. Here’s an copy/paste from my test setup that is fairly similar to what you were wanting to accomplish (I believe). Update and test it out and let me know if it gets you where you want to be!

    When using the apr shortcode inside an apr_loop, the loopScope allows you to specify *which* loop(scope) the field should reference. so in the following example, you can see that I want to refer to the Name of the restaurant on EACH Picture. This will be especially useful for building URLs that are hierarchical and require a name/slug/attribute from the parent record.

    
    [apr_loop]
    {{Name}} is the same as [apr field="Name"]
    {{Pictures|0|thumbnails|large|url}} is the same as [apr field="Pictures|thumbnails|large|url" single]
    [apr_loop1 field="Pictures"]
    This is a picture from [apr field="Name" loopScope="0"]
    <img src="{{thumbnails|large|url}}" />
    [/apr_loop1]
    <hr>
    [/apr_loop]
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘trouble using [apr field=] inside [apr_loop]’ is closed to new replies.