Code nhận diện mobile và desktop
{% macro display_layout() %} {% set ua = SERVER_HTTP_USER_AGENT %} {% set arrUA = ua|lower %} {% if arrUA|preg_match('/windows|ipod|ipad|iphone|android|webos|blackberry|midp/') and arrUA|preg_match('/mobile/') %} mobile {% elseif arrUA|preg_match('/mobile/') %} mobile {% else %} desktop {% endif %} {% endmacro %}
Sử dụng:
{% from '_functions' import display_layout %} {% set display = display_layout()|trim %} {% if display == 'desktop' %} Chức năng dành cho desktop {% else %} Chức năng dành cho mobile {% endif %}
Chia sẻ
|
|