V
V
Vitaly2015-01-02 14:39:21
PHP
Vitaly, 2015-01-02 14:39:21

How to pass php to smarty template via plugin?

Tell me how to pass this piece of php to a template built on smarty (version 3)

<?php
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
if ( $detect->isMobile() ): ?>
  <p>Mobile Content</p>
<? else: ?>
  <p>Default Content</p>
<? endif; ?>

A search on the Internet suggested that you need to write a plugin and output through it, because. {php} is not recommended. I rewrote this into a plugin, but how to pass a variable with an object to the template and how to build an if-else with it will not work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Galkin, 2015-01-02
@socengel

"but how to pass a variable with an object to the template and how to build an if-else with it will not work in any way."
You are trying to do a terrible thing. That's how it is more or less necessary.

<?php
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
$is_mobile = $detect->isMobile();

And pass the $is_mobile variable to the template.

X
xmoonlight, 2015-01-02
@xmoonlight

Use your own template: it seems to be not difficult and in capable hands reduces the load on the web server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question