Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions templates/catalog/_partials/product-details.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<div class="js-product-details tab-pane fade{if !$product.description} in active{/if}"
id="product-details"
data-product="{$product.embedded_attributes|json_encode}"
role="tabpanel"
>
{* Every block below is conditional, so the pane can come out with nothing in it. Capture it first and
emit the wrapper only when it holds something, so product.tpl can drop the tab instead of showing an
empty panel. Child themes overriding any block are unaffected - the blocks are unchanged. *}
{capture name='product_details_content'}
{block name='product_reference'}
{if !empty($product_manufacturer.id)}
<div class="product-manufacturer">
Expand Down Expand Up @@ -55,9 +54,14 @@
{/block}

{block name='product_out_of_stock'}
<div class="product-out-of-stock">
{hook h='actionProductOutOfStock' product=$product}
</div>
{* The six sibling blocks all guard their markup; this one emitted its wrapper even when no module
answered the hook, which is what left the pane holding a single empty div. *}
{capture name='product_out_of_stock'}{hook h='actionProductOutOfStock' product=$product}{/capture}
{if trim($smarty.capture.product_out_of_stock) !== ''}
<div class="product-out-of-stock">
{$smarty.capture.product_out_of_stock nofilter}
</div>
{/if}
{/block}

{block name='product_features'}
Expand Down Expand Up @@ -98,4 +102,22 @@
</div>
{/if}
{/block}
</div>
{/capture}

{* Keep the pane when it has content. When it has none it is only kept if there is no description tab,
because then this pane is the one carrying `active` and something has to be shown.

The answer is published as a variable rather than left for the caller to infer from this template's
output: in debug mode SmartyDevTemplate wraps every include in `<!-- begin ... -->` comments, so a
caller testing the rendered markup for emptiness would find it non-empty on every dev shop. *}
{assign var='product_details_has_content' value=(trim($smarty.capture.product_details_content) !== '') scope='root'}

{if $product_details_has_content || !$product.description}
<div class="js-product-details tab-pane fade{if !$product.description} in active{/if}"
id="product-details"
data-product="{$product.embedded_attributes|json_encode}"
role="tabpanel"
>
{$smarty.capture.product_details_content nofilter}
</div>
{/if}
31 changes: 19 additions & 12 deletions templates/catalog/product.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@
{/block}

{block name='product_tabs'}
{* Rendered up front so the nav can tell whether the Product Details tab has anything to show.
The partial decides that itself and returns nothing when it does not. *}
{capture name='product_details_pane'}
{block name='product_details'}
{include file='catalog/_partials/product-details.tpl'}
{/block}
{/capture}
<div class="tabs">
<ul class="nav nav-tabs" role="tablist">
{if $product.description}
Expand All @@ -152,15 +159,17 @@
{if $product.description} aria-selected="true"{/if}>{l s='Description' d='Shop.Theme.Catalog'}</a>
</li>
{/if}
<li class="nav-item">
<a
class="nav-link{if !$product.description} active js-product-nav-active{/if}"
data-toggle="tab"
href="#product-details"
role="tab"
aria-controls="product-details"
{if !$product.description} aria-selected="true"{/if}>{l s='Product Details' d='Shop.Theme.Catalog'}</a>
</li>
{if $product_details_has_content || !$product.description}
<li class="nav-item">
<a
class="nav-link{if !$product.description} active js-product-nav-active{/if}"
data-toggle="tab"
href="#product-details"
role="tab"
aria-controls="product-details"
{if !$product.description} aria-selected="true"{/if}>{l s='Product Details' d='Shop.Theme.Catalog'}</a>
</li>
{/if}
{if $product.attachments}
<li class="nav-item">
<a
Expand Down Expand Up @@ -190,9 +199,7 @@
{/block}
</div>

{block name='product_details'}
{include file='catalog/_partials/product-details.tpl'}
{/block}
{$smarty.capture.product_details_pane nofilter}

{block name='product_attachments'}
{if $product.attachments}
Expand Down
Loading