solved profile_sidebar.tpl - Headings Question

Ken Rich
Ken Rich
@ken-rich
3 years ago
926 posts
How can I make a header title not display if there is no content? For example, if someone has just joined but has not generated any stats, how can I prevent the Stats header from displaying in their profile?

I know I must modify this piece of code but I don't know what to add.


  {if isset($_conf.xxComplete_profile_stats) && $_conf.xxComplete_profile_stats == 'on'}
            {if isset($_conf.xxComplete_profile_stats) && $_conf.xxComplete_profile_stats == 'on'}
                    <div class="block">
                        <h3>{jrCore_lang skin=$_conf.jrCore_active_skin id="39" default="stats"}</h3>
                        <div class="block_content mt10">
                            <div style="padding-top:8px">

                                {capture name="template" assign="stats_tpl"}
                                {literal}
                                    {foreach $_stats as $title => $_stat}
                                    {jrCore_module_url module=$_stat.module assign="murl"}
                                    <div class="stat_entry_box" onclick="window.location='{$jamroom_url}/{$profile_url}/{$murl}'">
                                        {$title}: {$_stat.count|default:0}
                                    </div>
                                    {/foreach}
                                {/literal}
                                {/capture}
                                {jrProfile_stats profile_id=$_profile_id template=$stats_tpl}

                                <div class="clear"></div>
                            </div>
                        </div>
                    </div>
                {/if}

I am thinking, adding another && to the first line that basically says "and the stats are greater than zero". However, I don't know how to write it. Something like "&& $_stat.count > 0" but that doesn't work.


--

Ken Rich
indiegospel.net

updated by @ken-rich: 10/27/21 07:53:40AM
paul
@paul
3 years ago
4,326 posts
What I would try is instead of outputting the results of the jrProfile_stats call directly, assign it to a variable. You can then test the length of the variable and then show it if it has content. So the code might be something like -

{if isset($_conf.xxComplete_profile_stats) && $_conf.xxComplete_profile_stats == 'on'}
    {capture name="template" assign="stats_tpl"}
    {literal}
        {foreach $_stats as $title => $_stat}
            {jrCore_module_url module=$_stat.module assign="murl"}
            <div class="stat_entry_box" onclick="window.location='{$jamroom_url}/{$profile_url}/{$murl}'">
                {$title}: {$_stat.count|default:0}
            </div>
        {/foreach}
    {/literal}
    {/capture}
    {jrProfile_stats profile_id=$_profile_id template=$stats_tpl assign="xxxx"}
    {if strlen($xxxx) > 0}
         <div class="block">
              <h3>{jrCore_lang skin=$_conf.jrCore_active_skin id="39" default="stats"}</h3>
               <div class="block_content mt10">
                    <div style="padding-top:8px">
                          {$xxxx}
                     </div>
                 </div>
        </div>
    {/if}
{/if}

Note that we are assigning the stats output to variable $xxxx then test the length of that variable. If it has content we then output the variable directly.
You may need to experiment with the strlen condition as I'm not sure what its threshold may be.

Hope that makes sense.


--
Paul Asher - JR Developer and System Import Specialist
Ken Rich
Ken Rich
@ken-rich
3 years ago
926 posts
Hi Paul,

Thanks for the tip. I'll play with it and see if I can get it to work.


--

Ken Rich
indiegospel.net