• 虹色ミツバチ
  • freoカスタマイズメモ、テンプレート・プラグイン配布/officeTIPS
検索プラグイン
虹色ミツバチ

> Entry >freo>freoTips>プラグイン系TIPS> 同人イベントプラグインで未来のイベントがなかったときに特定の文字列を表示する方法

【freo】【freoTips】【プラグイン系TIPS】同人イベントプラグインで未来のイベントがなかったときに特定の文字列を表示する方法

同人イベントプラグインで未来のイベントのみ表示する方法を利用すると、未来のイベントのみ表示することができます。
この時、未来のイベントがなかった場合に特定の文字列を表示する方法は、たとえば以下のようにします。

<table>
<tbody>
<!--{foreach from=$plugin_events|smarty:nodefaults item='plugin_event'}-->
<!--{if $plugin_event.datetime|date_format:'%Y/%m/%d' >= $smarty.now|date_format:'%Y/%m/%d'}-->
{assign var='eventFlg' value='true'}
<tr>
    <td><a href="{$freo.core.http_file}/event/view/{$plugin_event.id}">{$plugin_event.datetime|date_format:'%Y/%m/%d'}<!--{if $plugin_event_files[$plugin_event.id].file}--><br /><img src="{$freo.core.http_url}{$smarty.const.FREO_FILE_DIR}plugins/event_files/{$plugin_event.id}/{$plugin_event_files[$plugin_event.id].file}" alt="{$plugin_event.title}" /><!--{/if}--></a></td>
    <td>
        <!--{if $plugin_event.url}--><a href="{$plugin_event.url}" target="_blank">{$plugin_event.title}</a>
        <!--{else}-->{$plugin_event.title}
        <!--{/if}-->
    </td>
    <td>
        <!--{if $plugin_event.space}--><!--{if $plugin_event.hall}-->{$plugin_event.hall} <!--{/if}-->{$plugin_event.space}<!--{/if}--><br /><!--{if $plugin_event.style}-->({$plugin_event.style}<!--{if $plugin_event.itakucircle}-->|<!--{if $plugin_event.itakuurl}--><a href="{$plugin_event.itakuurl}" target="_blank">{$plugin_event.itakucircle}様</a><!--{else}-->{$plugin_event.itakucircle}様<!--{/if}--><!--{/if}-->)<!--{/if}-->
    </td>
    <td>{$plugin_event.name}</td>
    <td>
        <!--{if $plugin_event.category_id}-->【カテゴリー:<a href="{$freo.core.http_file}/event?category_id={$plugin_event.category_id}">{$plugin_event_categories[$plugin_event.category_id].name}</a>】<br /><!--{/if}-->
        <!--{if $plugin_event_tags[$plugin_event.id]|smarty:nodefaults}-->【タグ:<!--{foreach from=$plugin_event_tags[$plugin_event.id]|smarty:nodefaults item='plugin_event_tag' name='loop'}--><a href="{$freo.core.http_file}/event?tag={$plugin_event_tag|smarty:nodefaults|escape:'url'}">{$plugin_event_tag}</a><!--{if !$smarty.foreach.loop.last}-->,&nbsp;<!--{/if}--><!--{/foreach}-->】<br /><!--{/if}-->
        <!--{if $plugin_event.coupling}-->カップリング:{$plugin_event.coupling}<br /><!--{/if}-->
        <!--{if $plugin_event.text}-->{$plugin_event.text|smarty:nodefaults|strip_tags|mb_truncate:20:'...'|escape}<!--{/if}-->
    </td>
</tr>
<!--{/if}-->
<!--{/foreach}-->
<!--{if $eventFlg != 'true'}-->
    <tr><td>次回のイベント参加は未定です。</td></tr>
<!--{/if}-->
</tbody>
</table>

解説するとこんな↓感じです。

<table>
<tbody>
<!--{$plugin_events配列を繰り返して表示するここから}-->
<!--{もしイベント開催日が今よりも未来だったらここから}-->
    {eventFlgというテンプレート内変数に'true'という値を代入する}
    ~繰り返す内容(イベント情報表示部分)~
<!--{もしイベント開催日が今よりも未来だったらここまで}-->
<!--{$plugin_events配列を繰り返して表示するここまで}-->
<!--{もし$eventFlgが'true'じゃなければここから}-->
    ~未来のイベントがなかった場合に表示する特定の文字列~
<!--{もし$eventFlgが'true'じゃなければここから}-->
</tbody>
</table>

今回は、条件を判断するのにsmartyで利用できるテンプレート変数を活用しています。
詳しくは下記サイトを参考にしてください。

I'll be NET|smartyのassignでテンプレート内変数を定義する方法

PHPを利用して特定の文言を表示する場合は下記サイトを参考にして下さい。

夏草生産農家|同人イベント&イベントリストプラグインをちょっと便利にするカスタマイズ

ページ移動

関連記事

ユーティリティ

Twitter

ページ上部へ