How to use include in smarty3 template engine - smarty

This is my first template for Prestashop 1.7. I use Starter theme. But now I have problem because I want to create new block.
addresses.tpl
{extends file='page.tpl'}
{block name='page_content_container'}
<div class="container">
<div class="account">
<h2 class="heading">
{block name='page_title'}
{l s='Your addresses' d='Shop.Theme.Customeraccount'}
{/block}
</h2>
<div class="box">
<section id="content" class="page-content page-addresses">
{foreach $customer.addresses as $address}
{block name='customer_address'}
{include file='customer/_partials/block-address.tpl' address=$address}
{/block}
{/foreach}
<footer>
<a href="{$urls.pages.address}" data-link-action="add-address">
{l s='Create new address' d='Shop.Theme.Actions'}
</a>
</footer>
</section>
</div>
</div>
</div>
{/block}
and page.tpl
{extends file='page.tpl'}
{block name='my_account_links'}
{include file='customer/_partials/my-account-links.tpl'}
{/block}
This file extend another page.tpl but there is no my_account_links block. the question is. Why I dont see my_account_links block in addresses.tpl. When I display the page.
Kind regards

You don't see your my_account_links block in addresses.tpl because you don't have any {block name='my_account_links'} in addresses.tpl.
If you want to display your page.tpl in your addresses.tpl, you have to "call" the block in your parent file and extends it in your child file ( page.tpl ). Like this :
Addresses.tpl
{block name='my_account_links'} <!-- YOUR my_account_links OF YOUR PAGE.TPL WILL BE HERE {/block}
{block name='page_content_container'}
<div class="container">
<div class="account">
<h2 class="heading">
{block name='page_title'}
{l s='Your addresses' d='Shop.Theme.Customeraccount'}
{/block}
</h2>
<div class="box">
<section id="content" class="page-content page-addresses">
{foreach $customer.addresses as $address}
{block name='customer_address'}
{include file='customer/_partials/block-address.tpl' address=$address}
{/block}
{/foreach}
<footer>
<a href="{$urls.pages.address}" data-link-action="add-address">
{l s='Create new address' d='Shop.Theme.Actions'}
</a>
</footer>
</section>
</div>
</div>
</div>
{/block}
And in your page.tpl :
{extends file='addresses.tpl'}
{block name='my_account_links'}
{include file='customer/_partials/my-account-links.tpl'}
{/block}
Now, with this, your page.tpl ( the block 'my_account_links' ) will be display in your addresses.tpl

Related

Section not displayed on browser

I am using laravel 6. I have problem with my section where its not display the result on browser. I have place #yield on my layout but half of section still not displayed
here my code
#section('main-content')
<section class="breadcrumbs">
<div class="container">
<div class="d-flex justify-content-between align-items-center">
<h2>Detail Tanaman</h2>
</div>
</div>
</section>
<!-- ======= Blog Section ======= -->
<section id="blog" class="blog">
<div class="container" data-aos="fade-up">
<div class="row">
<div class="col-lg-8 entries">
<article class="entry">
<div class="entry-img">
<img src="/img/bonsai.jpg" style ="width:100%; height:100%;" alt="" class="img-fluid">
</div>
<h2 class="entry-title">
{{$data->nama_tanaman}}
</h2>
here my layout
<a class="carousel-control-prev" href="#heroCarousel" role="button" data-bs-slide="prev">
<span class="carousel-control-prev-icon bx bx-chevron-left" aria-hidden="true"></span>
</a>
<a class="carousel-control-next" href="#heroCarousel" role="button" data-bs-slide="next">
<span class="carousel-control-next-icon bx bx-chevron-right" aria-hidden="true"></span>
</a>
</div>
</section><!-- End Hero -->
#yield('main-content')
You forget to add extends('master') (master is the name of your master page file) at the first of your section like:
In your master:
#yield('main-content')
In your section file:
#extends('master')
#section('main-content')
...
#endsection

Smarty alternate view elements in foreach loop

I am trying to figure out a way to cycle through the inner loop view items in the following manner:
First:
<div class="col-sm-6">
<h3 class="padding-bot-20">{$row->service}</h3>{$row->content}
</div>
<div class="col-sm-6">
<img class="img-responsive" src="{$this->images->frontend_check_image($row->main_image)}" alt="Service">
</div>
Second:
<div class="col-sm-6">
<img class="img-responsive" src="{$this->images->frontend_check_image($row->main_image)}" alt="Service">
</div>
<div class="col-sm-6">
<h3 class="padding-bot-20">{$row->service}</h3>{$row->content}
</div>
and so on... so the presentation is content/image, image/content, content/image .etc.
This is the main code:
<div class="container">
{if count($row_services) == 0}
No services published.
{else}
{assign var=i value=0}
{foreach from=$row_services item=row}
<div class="row scroll-animated-from-bottom {if $i > 0}padding-top-50{/if}" id="service-data-1">
<div class="col-sm-6">
<h3 class="padding-bot-20">{$row->service}</h3>{$row->content}
</div>
<div class="col-sm-6">
<img class="img-responsive" src="{$this->images->frontend_check_image($row->main_image)}" alt="Service">
</div>
</div>
{capture assign=i}{$i+1}{/capture}
{/foreach}
{/if}
</div>
I know how to accomplish this is php, but I'm unsure how to do it in smarty. I'm trying to avoid having any child views.
This is the best I could come up with. If anyone has a more elegant solution, feel free to share:
<div class="container">
{if count($row_services) == 0}
No services published.
{else}
{assign var=i value=0}
{foreach from=$row_services item=row}
<div class="row scroll-animated-from-bottom {if $i > 0}padding-top-50{/if}" id="service-data-1">
{if ($i % 2 == 0)}
<div class="col-sm-6">
<h3 class="padding-bot-20">{$row->service}</h3>{$row->content}
</div>
<div class="col-sm-6">
<img class="img-responsive" src="{$this->images->frontend_check_image($row->main_image)}" alt="Service">
</div>
{else}
<div class="col-sm-6">
<img class="img-responsive" src="{$this->images->frontend_check_image($row->main_image)}" alt="Service">
</div>
<div class="col-sm-6">
<h3 class="padding-bot-20">{$row->service}</h3>{$row->content}
</div>
{/if}
</div>
{capture assign=i}{$i+1}{/capture}
{/foreach}
{/if}
</div>

prestashop: How to display accessories of a product if product has properties?

In product.tpl below code needs some more effective conditions.
{if $features}
<section class="page_product_box toggle_frame datasheet" style="display:none;">
<h3 class="toggle">{l s='Data sheet'}<i class="icon-toggle icon-minus-sign-alt"></i></h3>
<div class="features">
{if isset($features) && $features}
{foreach from=$features item=feature}
<div id="feature-icon"><img class="feature" title="{$feature.detail}" src="{$img_ps_dir}f/{$feature["id_feature"]}.jpg" width="65" height="65"/></div>
{/foreach}
</div>
</section>
{/if}

Class for first element in smarty foreach

I'm trying to add some smarty to my template , to first element i want to give
<div class="item active">
and for next elements
<div class="item">
I tried to do something like this:
{foreach $imageCollection as $image key=slider}
{if $slider < 1}
<div class="item active">
<img class="img-responsive" src="{$image->getPath('1400x469')}" alt="caption1" />
<div class="carousel-caption">
{else}
<div class="item">
<img class="img-responsive" src="{$image->getPath('1400x469')}" alt="caption1" />
<div class="carousel-caption">
{/if}
{/foreach}
It's doesn't work, all elements are displaying with
<div class="item active">
use #first:
{foreach $imageCollection as $image}
<div class="item {if $image#first}active{/if}">
...
{/foreach}
The correct syntax for getting the index key in Smarty is as following:
{foreach from=$imageCollection item=image key=slider}
// Your code
{/foreach}

Login menu not appearing when created using meteor

I am new to Meteor of course for developing filed as well. I have created a login UI using meteor, but it is not visible. I am able to see through inspect element using console. Can some one tell me what went wrong.
<body>
<div class="container">
{{> header}}
<div id="main" class="row-fluid">
{{renderPage}}
</div>
</div>
</body>
<template name="header">
<header class="navbar">
<div class="navbar-inner">
<a class="brand" href="/">Jobboard</a>
<ul class="nav">
</ul>
<ul class="nav pull-right">
<li>{{loginButtons}}</li>
</ul>
</div>
</template>
You need to close your <header> tag. Use consistent indentation to make these issues more obvious:
<body>
<div class="container">
{{> header}}
<div id="main" class="row-fluid">
{{renderPage}}
</div>
</div>
</body>
<template name="header">
<header class="navbar">
<div class="navbar-inner">
<a class="brand" href="/">Jobboard</a>
<ul class="nav">
</ul>
<ul class="nav pull-right">
<li>{{loginButtons}}</li>
</ul>
</div>
</header>
</template>

Resources