We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Limiting the output of a fluid field

How Do I?

Mandarax's avatar
Mandarax
21 posts
7 years ago
Mandarax's avatar Mandarax

I love the concept of the new fluid field, it offers the best option for giving the client more freedom in content layout while giving the designer the ability to lock down style and prevent a horror-show of mixed formatting.

BUT….

There’s one huge issue I’ve come across that renders the fluid field almost completely useless for the way I build my sites. I should say I’m very happy to be proved wrong in my assumptions and if I’ve missed something glaringly obvious in the docs then so be it.

My issue is this, fluid field output cannot be controlled by a limit parameter so each loop will output all instances of the fields within it.

As an example I’ve created a fluid field called {content-fluid} into which I’ve added a textarea {body-text} and a file field {image}. All good so far, this allows my clients to drag images and paragraphs into whatever order they like.

{content-fluid}

{content-fluid:body-text}
{content}
{content-fluid:body-text}

{content-fluid:image}
{content}
{content-fluid:image}

{/content-fluid}

This works nicely on a blog entry page. But when trying to create a listing page based on the same fields it’s seemingly impossible to limit the output of the fluid field to just a single instance of {body-text} or {image} if the entry contains multiple instances of each.

The behaviour I expected based on how Grid fields work is this:

{content-fluid}

{content-fluid:body-text limit="1"}
{content}
{content-fluid:body-text}

{content-fluid:image limit="1"}
{content}
{content-fluid:image}

{/content-fluid}

But that does not seem to work. The loops will simply output every instance of the the fluid field “children”

If anybody that has made it through all of that has any ideas I would love to hear them!

       
James Catt's avatar
James Catt
17 posts
7 years ago
James Catt's avatar James Catt

Yeah I think this is probably going to involve a feature request.

I’d like to be able to do some related things—change the output based on count (i.e., if it’s the 2nd image, change the output somehow), as well as limit the use of certain content types (i.e., have a certain type of subfield that can only be used once).

I’ve tried all the usual suspects ({count}, {total_results}, etc), but none of them seem to be supported for the Fluid field itself—only embedded Grid/Relationship fields. There’s also no mention of anything like this in the docs.

       
Derek Jones's avatar
Derek Jones
7,561 posts
7 years ago
Derek Jones's avatar Derek Jones

Indeed, and we have plans for metadata variables, conditionals and such. It just did not make the initial dot-oh release of the new feature. Thanks for the feedback!

       
James Catt's avatar
James Catt
17 posts
7 years ago
James Catt's avatar James Catt

Yeah I figured as much. Looking forward to it landing! 😊

       
Mandarax's avatar
Mandarax
21 posts
7 years ago
Mandarax's avatar Mandarax

OK. At least I know I’m not losing my mind (in relation to this anyway!!!).

Good to know there’s more coming for the fluid field, now that I know, I can work within the limitations or park it until a later date.

Thanks.

       
ngage's avatar
ngage
1 posts
7 years ago
ngage's avatar ngage

Yup! Looking forward to this too 😊

       
Stefan Rechsteiner's avatar
Stefan Rechsteiner
442 posts
7 years ago
Stefan Rechsteiner's avatar Stefan Rechsteiner

+1

       
varnbyrde's avatar
varnbyrde
4 posts
6 years ago
varnbyrde's avatar varnbyrde

Once again, Switchee to the rescue: https://github.com/croxton/Switchee

{my_fluid_field}
{my_fluid_field:my_grid}
 {content}
  {exp:switchee variable="{content:my_relationship:my_dropdown}{content:my_dropdown}{/content:my_relationship:my_dropdown}" parse="inward"}
   {case value="my_dropdown_value1"}
    KAMAKAZI???!!!
   {/case}
   {case value="my_dropdown_value2"}
    WAZA KUZI!
   {/case}
  {/exp:switchee}
 {/content}
{/my_fluid_field:my_grid}
{/my_fluid_field}
       
Derek Jones's avatar
Derek Jones
7,561 posts
6 years ago
Derek Jones's avatar Derek Jones

Hey varnbyrde, this is a pretty old thread, and the metavariables mentioned before were released a long time ago. What problem were you having that had you resort to Switchee? It doesn’t look necessary here, and in most cases, will perform worse than native conditionals on all versions of ExpressionEngine after 2.9.

       
varnbyrde's avatar
varnbyrde
4 posts
6 years ago
varnbyrde's avatar varnbyrde

Hi, Derek,

I guess my application is a bit different than the original question, if you’ll forgive this in the thread. I have a pretty complex assortment of field types being drawn into fluid. In my code above, I have not found a way to natively check for a value in one field type pair three levels deep ( fluid / grid / relationship / dropdown), and then proceed with a separate field type pair output (fluid / grid / relationship / grid) based on the first but outside of its context. It seems the conditionals are restricted to values within the individual pair.

Based on my original code, what would be your native EE solution? I need both ‘cases’ to output separate field pairs, outside the scope of the dropdown.

Thanks in advance.

       
Derek Jones's avatar
Derek Jones
7,561 posts
6 years ago
Derek Jones's avatar Derek Jones

> I need both ‘cases’ to output separate field pairs

Can you provide a real content and tag sample besides KAMAKAZI and WAZA KUZI? There’s not enough context to give you specific advice other than doing what you are already doing, but using native conditionals instead of Switchee.

       
varnbyrde's avatar
varnbyrde
4 posts
6 years ago
varnbyrde's avatar varnbyrde

I took your advice and played around with a native solution, removing Switchee. A bit convoluted at the moment, but I’d didn’t know something like this would work inside fluid:

{my_fluid_field}
    {my_fluid_field:my_grid_1}
        {content}
            {if '{content:my_relationship_1:my_dropdown}' == 'my_val' && '{content:my_relationship_2:my_grid_2}{my_grid_2:count}{/content:my_relationship_2:my_grid_2}' == 1}
                {content:my_relationship_3:my_grid_3}{my_grid_3:my_assets:url}{/content:my_relationship_3:my_grid_3}
            {if:else}
            {/if}
        {/content}
    {/my_fluid_field:my_grid_1}
{/my_fluid_field}
       
Derek Jones's avatar
Derek Jones
7,561 posts
6 years ago
Derek Jones's avatar Derek Jones

Looks like you don’t have anything in the if:else block, so you should be able to remove that. Also I think you can eliminate the quotes and brackets from those conditionals for even more efficient (and quote-safe) parsing, e.g.:

{if content:my_relationship_1:my_dropdown == 'my_val' && content:my_relationship_2:my_grid_2:total_rows == 1}

The second part of that conditional I’m assuming you’re wanting to know how many rows.

       
varnbyrde's avatar
varnbyrde
4 posts
6 years ago
varnbyrde's avatar varnbyrde

Thanks, I’ll modify.

       
Mandarax's avatar
Mandarax
21 posts
about 6 years ago
Mandarax's avatar Mandarax

Almost a year and a half since I had the first problem with fluid fields and decided to try again. Still no joy. I have to say I find the documentation confusing and the syntax for fluid fields does not seem to follow the same format as relationships for instance.

Is it possible to apply parameters to either the fluid field outer tag or the inner {content} tag. I’ve tried applying the :first limiter to both and still cant seem to limit the field output on a listing page.

Any help appreciated. Thanks

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.