sruupl / batflat

Lightweight, fast and easy CMS for free. Bootstrap ready. https://batflat.org
MIT License
135 stars 53 forks source link

If !empty - site.php not working #110

Open Dejmienwp opened 3 years ago

Dejmienwp commented 3 years ago

Witam. Mam pętle do wyświetlania wydarzeń. Niestety nie działa if !empty

{if: !empty($allEvents)}
{loop: $allEvents}
<div class="uk-flex uk-margin-small">
    <div class="">
        <div class="uk-text-light" style="background-color:#f08231;padding: 10px 15px;color:#fff;font-weight: 600;">{$value.dateday}</div>
    </div>
    <div class="uk-margin-small-left">
        <h5 class="uk-margin-remove" style="color:#f08231;">{$value.name}</h5>
        <p class="uk-margin-remove uk-text-small">{$value.dates} | <span>{$value.desc}</span></p>
    </div>
</div>
{/loop}
{else}
<div>
    Aktualnie brak wydarzeń na naszych obiektach.
</div>
{/if}

Site.php

   public function init()
    {
        $newDate = $this->core->db('events')->where('datestart', '<', date('Y-m-d H:i'))->update(
            [   
                'status' => 'unactive'
            ]);

        $this->tpl->set('allEvents', function () {
            return $this->_getAllEvents();
        });

        $this->tpl->set('events', function () {
            return ['form' => $this->_insertForm()];
        });
    }

    private function _insertForm()
    {
        return $this->draw('form.html');
    }

    public function _getAllEvents()
    {
        $rows = $this->db('events')->where('status', 'activ')->asc('datestart')->toArray();
        $result = [];        

        foreach ($rows as $row) {

            $row['dateday'] = date('d', strtotime($row['datestart']));
            $row['dates'] = (new \DateTime(date('d-m-Y H:i', strtotime($row['datestart']))))->format('Mx Y H:i');
            $keys = array_keys($this->core->lang['blog']);
            $vals = array_values($this->core->lang['blog']);
            $row['dates'] = str_replace($keys, $vals, strtolower($row['dates']));
            $result[] = $row;
        }  
        return $result; 
     }

Jakiś Pomysł jak to naprawić ? :/

Dejmienwp commented 2 years ago

Any Idea why {if: !empty()} not working on site? In /admin its good i wanna create event module when not active events i have any div "xxx "

michu2k commented 2 years ago

Hi @Dejmienwp It is hard to say where is the problem. Have you tried to print $result in the form.html file? Maybe this variable is not passed to the view.