2

I upgraded to Assets 2.1 yesterday and am experiencing a problem when a non-required Assets 2.1 field in a Matrix row is empty. On a single-entry template (limit=“1” and require_entry=“yes” parameters in my exp:channel:entries tag) this situation is causing the {if no_results} conditional to be invoked. Selecting a file for the empty, non-required, Assets field and re-saving the entry fixes the problem.

Thanks in advance for your help.

Matrix 2.5.3 ExpressionEngine 2.5.2 Build 20120606

Here is template code that will trigger the issue:

{exp:channel:entries channel="videos" limit="1" status="open" disable="categories|category_fields|pagination|member_data" require_entry="yes"}{if no_results}{redirect="404"}{/if}<!doctype html>
<html lang="en">
<head>
<title>Page Title</title>
</head>
<body>

<h2>Videos</h2>

{sidebar_videos limit="1"}

<iframe src="//www.youtube.com/embed/{youtube_video_id}"></iframe>
<p>{youtube_caption}</p>

{/sidebar_videos}

<h3>All Videos</h3>

<ul id="videothumbs">

{sidebar_videos}

<li><a href="/features/videos/{entry_id}/{row_id}" title="{youtube_title}”>{youtube_thumbnail}<img src="{url}" alt="{alt_text}">{/youtube_thumbnail}</a></li>

{/sidebar_videos}

</ul>

</body>
</html>
{/exp:channel:entries}

{sidebar_videos} is my Matrix field, which is not required. {youtube_thumbnail} is the problem Assets field within the Matrix field. The other columns in the Matrix field are:

{youtube_title} (Text/required)

{youtube_video_id} (Text/required)

{youtube_caption} (Wygwam/required)

{youtube_thumbnail} (Assets/not required)

  • Hey jauses - can you post your full template code? I'd like to test this and want to make sure I'm recreating what you've done. Thank you! – Lisa Apr 10 '13 at 19:50
  • Updated my real answer with the fix for you. :) – Lisa Apr 12 '13 at 17:41
1

Edit again! jauses - can you try changing line 1324 in ft.assets.php file from

if (! $data)

to

if (! $data && $this->var_id)

? That should fix this up for you.

Thank you!

| improve this answer | |
  • I can replicate that problem, too. It’s actually failing even if I limit the output to a single entry that has a populated Assets field. The required_entry parameter seems to be the problem child here. Removing it fixes the problem, although then, of course, the {if no_results} conditional fails. – jauses Apr 11 '13 at 17:55
  • Yep, it's an interesting one - I have submitted it as a bug for 2.1 Thank you jauses! – Lisa Apr 11 '13 at 20:10
  • Boom! That did the trick. Thanks so much! – jauses Apr 13 '13 at 19:15
  • My pleasure, jauses! – Lisa Apr 15 '13 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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