0

I have a channel with a playa field where users can select a block of content to insert into a page.

Is there a way that I can specify a default child entry to display if the playa field is left blank?

1 Answer 1

1

Yes. One approach would be using a conditional based on no_children variable:

{exp:playa:children field="your_field"}
    {if no_children}
        No children found...display fallback.
    {/if}
{/exp:playa:children}

Or you might find that using a conditional based on the {exp:playa:total_children} tag is better suited:

{if "{exp:playa:total_children field='your_field'}"}
    No children found...display fallback.
    Perhaps open a channel entry loop here to show your fallback child
{/if}
2
  • I considered those options, but the problem is, I want to display a specific child entry, if none is specified, so my conditional would have to be another duplicate instance of my playa code, with a hard-coded entry_id. I'm trying to find a way to avoid doing that.
    – artmem
    Jan 16, 2014 at 21:51
  • I don't think you'll be able to avoid hard-coding an entry_id since you have to specify a child to show (either using Playa or a plain channel:entries tag). I take it it's the repeated html you don't care for? You could put the html in a snippet.
    – Alex Kendrick
    Jan 16, 2014 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.