V
V
Vladislav Samoilov2015-03-29 01:52:27
PHP
Vladislav Samoilov, 2015-03-29 01:52:27

I can not organize work with tpl templates. How to display two separate elements for only one template?

In general, you need to make sure that when you go to a non-main page, the slider is not shown.
There is an index.tpl file.
It contains a template for displaying invariable items on the site, such as a header, menu, etc.
the rest of the templates are responsible for what is in "content".
We want the slider to be under the header, but active only on the main page.
If I insert it into the header of index.tpl, then it is displayed on absolutely all pages
of index.tpl

<html>
<body>
<header id="header">
<div class="menu"> ... </div>
</header>
<!-- Вот тут я вставляю тот самый slider. Сразу под шапкой сайта -->
<section id="slider">...</selection>

<!-- Вся страница -->
<div id="main">
    <!-- Основная часть (То место, куда вставляется все другие шаблоны (main.tpl, cart.tpl и т.д.))-->
    <div id="content">
        {$content}
    </div>
    <!-- Основная часть (The End) -->

    <div id="left">
        ...
    </div>
</div>
</body>
</html>

900f90f059b04b6cb7df63578d73d212.jpg
If I insert a slider in the main.tpl file, then it is displayed in the size of the div, that is, not from edge to edge, as it should be.
main.tpl
{* Главная страница магазина *}

{* Для того чтобы обернуть центральный блок в шаблон, отличный от index.tpl *}
{* Укажите нужный шаблон строкой ниже. Это работает и для других модулей *}
{$wrapper = 'index.tpl' scope=parent}

{* Канонический адрес страницы *}
{$canonical="" scope=parent}

{* Заголовок страницы *}
<h1>{$page->header}</h1>

{* Тело страницы *}
{$page->body}
<!-- Вот тут я вставляю тот самый slider -->
<section id="slider">...</selection>

{* Рекомендуемые товары *}
{get_featured_products var=featured_products}
{if $featured_products}
<!-- Список товаров-->
<h1>Рекомендуемые товары</h1>
...

64114dfe49dd45d894c1aa3f7f3387dc.jpg
I tried to position the slider using css, but it didn't work either:
8da4a627427740bbbc150f5301127704.jpg
I had an idea to create something like {$content}, but under the header, but I'm not sure how to implement it. I tried to insert PHP conditions in index.tpl
index.tpl
{php}
   if ($_SERVER['REQUEST_URI']=='/'){
{/php}
       <section id="slider">...</selection>
{php}
   }
{/php}

and also like this:
{php}
   if ($_SERVER['REQUEST_URI']=='/'){
       echo "<section id='slider'>...</selection>";
   }
{/php}

and without echo, and the usual SMARTY conditions:
index.tpl
if $_SERVER['REQUEST_URI']=='/'{ <section id="slider">...</selection> }

But the result was not displayed
This is how it should ideally be:
test.i
2b61ce8946f14c44b3c5dbae9b374099.jpg
test.i/cart
075a0663d68f491caa802db448d21443.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lnked, 2015-03-29
@MusArtVlad

Try like this

{if $smarty.server.REQUEST_URI == "/"}
<section id="slider">...</selection>
{/if}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question