smarty if empty else smarty value

32.9k views Asked by At

I have smarty value if it empty need another result

{get_video_meta video_id=$video_data.id key='test'}

This value print "test" If this value is empty else how can I use?

 {if !empty({get_video_meta video_id=$video_data.id key='test'})} 
  No value
 {else}
 {get_video_meta video_id=$video_data.id key='test'}
{/if}

This code not work

2

There are 2 answers

2
IMSoP On BEST ANSWER

You could use the {capture} function to capture the output into a variable, then choose what to do with it:

{capture name="video_meta"}{get_video_meta video_id=$video_data.id key='test'}{/capture}
{if empty($smarty.capture.video_meta)}
 No value
 {else}
 {$smarty.capture.video_meta}
{/if}
2
cn007b On

You can assign value to variable:

{if empty($code)}
    {assign var='code' value='404'}
{/if}

but i suppose that you need something like:

{if empty($video_data.id)}
    No value
{else}
    {get_video_meta video_id=$video_data.id key='test'}
{/if}

because get_video_meta - it's smarty plugin, and you can't use it like you try to use...

In foreach:

{foreach from=$video_data key=k item=v}
    {if empty($k)}
        No value
    {else}
        {get_video_meta video_id=$v.id key=$k}
    {/if}
{/foreach}