How to effectively make up templates for mobile devices on OkayCMS

Categories

At the moment, OkayCMS uses two functions so far:

  • is_mobile - a function to determine the client's mobile device when entering the site;
  • is_tablet - a function to determine the client's tablet device when entering the site;

These functions are available in all tpl files of the client template and are represented in the latter as a boolean variable and .

Everyone knows that responsive templates have the disadvantage of "hiding" unnecessary parts on mobile devices with the display: none property, but that still doesn't make the page easier to load on mobile.

The very first enemy of the client is a banner. You can have cool banners on the main page of the site, in the amount of 5 megabytes, but on mobile, they are often hidden so that they do not take up space. But why just make them invisible and load them if you can exclude them from the template altogether?

Actually, we tried to solve this issue by adding functionality that will allow layout designers to competently manage templates.

For example, to hide a banner from mobile, now it is enough to write like this:

 {if! $ is_mobile}
{get_banner var = banner_group1 group = 'group1'}
{if $ banner_group1-> items}
<div class = "container hidden-md-down">
<div class = "fn-slick-banner_group1 okaycms slick-banner">
{foreach $ banner_group1-> items as $ bi}
<div>
{if $ bi-> url}
<a href="""$bi-> url} "target =" _blank ">
{/ if}
{if $ bi-> image}
<img src = " " alt = "" title = "
<span class = "slick-name">

</span>
{if $ bi-> description}
<span class = "slick-description">

{if $ bi-> url}
</a>
{/ if}
</div>
{/ foreach}
</div>
</div>
{/ if}
{/ if}


Since the variable is_mobile, when entering from a mobile, will return TRUE, this condition {if! $ Is_mobile} will not work and the code with the banner will not load on our page, which will already give a good increase in speed when it loads.

This is just the simplest example of how you can simplify your template. On a more global scale, you can make separate convenient menus for mobile or tablets. In practice, I often met a situation when there are at least 2 menus on a page, only one is hidden on devices from 480 px, and the second is used as a desktop one. Which basically creates more code on the page.

We hope that this functionality will not pass by, and in the development of templates, people will use it, thereby creating more lightweight and modern templates, from a technical point of view.

Comments 3
Виталий
31.07.2017, 23:57
Возможность переключать шаблон - не самый главный плюс подхода с отдельным мобильным и десктопным шаблоном.
Mavr
07.06.2017, 14:05
Виталий, извините, а зачем на мобильном устройстве нужна возможность принудительного включения шаблона для десктопа?
Виталий
27.10.2016, 13:07
Лично мне больше нравится идея автосмены шаблона при заходе с разных устройств, который я выложил на форуме. Плюс этого метода в том, что есть возможность принудительно переключать шаблон. И второе, что код отдельных шаблонов более простой и понятный, лишенный всяких ограничений. Минус - что надо разрабатывать и вносить правки в два шаблона. Но несомненно, то что появилась функция определения устройства, это полезно. Это не исключает даже использования её при моем подходе.
Write your comment
log in
Download OkayCMS
version 4.5.0
Subscribe to the newsletter
You will receive a selection of useful articles on working with the site on OkayCMS, discounts on modules and templates