Smarty if empty another smart value

I have a smarty value, if it is empty, I need a different result

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

This value print "test" If this value is empty, 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 does not work

+4
source share
2 answers

You can use the function{capture} to output the output to a variable, and 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}
+8
source

You can assign a value to a variable:

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

but I suppose you need something like:

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

because it get_video_metais smarty plugin and you cannot use it as 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}
+1
source

All Articles