4

I am trying to use Low Variables, Playa, and a "Features" channel to allow me to select which (3-4) features will be displayed on the Home page. The intent is that either a News, Project, or (Structure) Page may be selected (but never more than one of those) or some unrelated content (body, url, file) may be entered. This is to allow maximum flexibility. Within the "Features" channel there are these fields:

"Features" Channel

  • title
  • feature_body (textarea -- required)
  • feature_related_news (Playa -- select up to 1 entry from "News" channel)
  • feature_related_project (Playa -- select up to 1 entry from "Projects" channel)
  • feature_related_page (Playa -- select up to 1 entry from "Pages" channel)
  • feature_URL (text input -- optional, only entered if no related item)
  • feature_image (file)

Low Variables

  • Variable: lv_settings_home_features_items (Playa -- select up to 4 entries from "Features" channel, drag and drop to reorder)

I can tell that the variable is being populated (example output: [93] [rainfall-news] Rainfall News [94] [check-out-our-work] Check Out Our Work [95] [donate] Donate).

Home Template

Each of the different types of related items (news, project, page, or other) requires slightly different formatting and field names.

I would like to do something like this:

<div class="row">
     {exp:playa:children var="lv_settings_home_feature_items" limit="3"}
 <div class="column one-third">
 {if feature_related_news}
      {related_entries id="feature_related_news"}
      <a href="{page_url}"><img src="{news_image:feature3}" alt="" /></a>
      <h3><a href="{page_url}">{/related_entries}{title}</a></h3>
 {if:elseif feature_related_project}
      {related_entries id="feature_related_project"}
      <a href="{page_url}"><img src="{project_image:feature3}" alt="" /></a>
      <h3><a href="{page_url}">{/related_entries}{title}</a></h3>
 {if:elseif feature_related_page}
      {related_entries id="feature_related_page"}
      <a href="{page_url}"><img src="{page_image:feature3}" alt="" /></a>
      <h3><a href="{page_url}">{/related_entries}{title}</a></h3>
 {if:else}
       {feature_image}
           {if feature_url != ""}<a href="{feature_url}">{/if}<img src="{url:feature3}" alt="" />{if feature_url != ""}</a>{/if}
       {/feature_image}
      <h3>{if feature_url != ""}<a href="{feature_url}">{/if}{title}{if feature_url != ""}</a>{/if}</h3>
 {/if}
      <p>{feature_body}</p>
 </div>
 {/exp:playa:children}
</div>

The code above has related_entries instead of the applicable Playa code. I started out with relationship fields in the Features channel but then changed them to Playa fields. The code worked when I used a exp:channel:entries channel="Features" to wrap the entire thing (and just outputted the 3 most recent Features), but once I put the Low Variable in and outer Playa tags on it doesn't work.

The Playa documentation says that to use nested relationships you need to use embeds. How would I structure those to achieve my goal? Or is there some other way? How do I pull the different chunks out of the LV?

1 Answer 1

4

If you want to output the entries that you selected in the LV-Playa field, use the Parse (or its alias: Pair) tag. You can then use any of the parameters can use with a playa:children tag. So, for example:

{exp:low_variables:pair var="lv_settings_home_feature_items" limit="3"}
    ...more code here...
{/exp:low_variables:pair}

To get to the other related fields, don't use the native relationship syntax like you're ding, but use Playa tags or the var-pair syntax:

{feature_related_news}
    ...code here...
{/feature_related_news}
4
  • How do I pull the related info in (the "related entries" part)? Do I use Playa tags for those parts?
    – Amy Witty
    Commented Jan 23, 2013 at 19:04
  • You should be able to use the Playa tags or use the var-pair syntax: {feature_related_news} ... {/feature_related_news} Updating my answer to include that.
    – Low
    Commented Jan 23, 2013 at 19:09
  • It's still not working. If I take out the "{related_entries ...}" tags altogether, it pulls the correct {title} and {page_body}; however, the {page_url} is missing the first segment and the image is missing.
    – Amy Witty
    Commented Jan 23, 2013 at 19:19
  • Oh, I added the tags in as {feature_related_news} and similar, and I'm close... A little broken still but closer...
    – Amy Witty
    Commented Jan 23, 2013 at 19:22

Your Answer

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

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