查看页面加载时的统计信息 [英] check stats when the page is load

查看:77
本文介绍了查看页面加载时的统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的树枝文件中,我想在页面加载时检查状态( ON / OFF)。

In my twig file i want to check the status ("ON/OFF") when the page load.

一个示例将是- Dell是主机名,因此在页面加载时,应从实体检查状态,是否为 on / off 。如果为开,则应为绿色(btn-成功),如果为关,则应为红色(btn-danger)。

An example will be--- "Dell" is a host name, so when the page load it should check the status from entity whether it is "on/off". If it is ON, it should be green (btn-success) and if it is OFF it will be red ( btn-danger ).

我的实体名称为 userinfo,我想检查其为True还是false

My entity name is "userinfo" and i want to check whether it is True or false in the button when the page load.

这是我尝试实现的方法,但是我认为我做错了---

This is what i try to implement, but i think i am doing it wrong ---

{if({ userinfo.stats=false }){ btn btn-danger}else {}}

{if({ userinfo.stats=true }){ btn btn-success}else {}}

这是我的按钮组- -

                    <td>
                        <div class="btn-group" data-toggle="buttons-radio">
                            <button class="btn btn-primary btn-xs myOn-button" ><i class="fa fa-check"></i> {% trans %}On{% endtrans %}</button>
                            <button class="btn btn-default btn-xs myOff-button" ><i class="fa fa-remove"></i> {% trans %}Off{% endtrans %}</button>
                        </div>
                    </td>

有人知道如何解决这个问题。

Do anyone knows how to solve this problem. Thanks in advanced.

推荐答案

如果需要使用 {%

{% if userinfo.stats %}
      {% set newClass = 'off' %}
{% else %}
      {% set newClass = 'on' %}
{% endif %}

或直接在按钮中

<button class="btn btn-primary btn-xs {% if userinfo.stats %}myOn-button{% else %}myOff-button{% endif %}" ><i class="fa fa-check"></i> {% trans %}On{% endtrans %}</button>

这篇关于查看页面加载时的统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆