I have a question regarding the use of templates and categories in News module. Is it possible to call different templates for different categories? For example:
- first news summary post appears in following order: photo on the left, text on the right, category is "PressLeft" (I made this template and it works);
- second news summary post should appear like: photo on the right, text on the left, category is "PressRight" (I made this but don't know how to make it work);
- third news summary post is like the 1st one, fourth is like the 2nd one etc...
I'm not that familiar with smarty but from what I have learned about it so far, I thought there must be a way to connect category and template. Here is the example of what I have right now but it's only template based and it worked perfectly until it grew too big:
https://sevenandcounting.studioides.com ... page=press
My idea was to have one template with two different parts with conditional behaviour based on a syntax I'm not able to create :
Code: Select all
<!-- Start News Display Template -->
{foreach from=$items item=entry}*******
<div class="row justify-content-center no-gutters press-black mb-5 mb-lg-0">
<div class="col-lg-6">
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="text-center">
{if $field->type == 'file'}
{if isset($field->value) && $field->value}
<img class="img-fluid" src="{$entry->file_location}/{$field->value}"/>
{/if}
{elseif $field->type == 'linkedfile'} {* also assume it's an image... *}
{if !empty($field->value)}
<img class="img-fluid" src="{file_url file=$field->value}" alt="{$field->value}"/>
{/if}
{else}
{/if}
</div>
{/foreach}
{/if}
</div>
<div class="col-lg-6">
<div class="bg-black text-center h-100 project">
<div class="d-flex h-100">
<div class="project-text w-100 my-auto text-center text-lg-left">
{if $entry->summary}
<h4 class="text-white">
{$entry->title}
</h4>
<p class="mb-0 text-white-50">
{$entry->summary}
</p>
<hr class="d-none d-lg-block mb-0 ml-0">
{/if}
{if isset($entry->extra)}
<div class="NewsSummaryExtra">
{$entry->extra}
{cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue}
</div>
{/if}
</div>
</div>
</div>
</div>
</div>
{elseif item=entry category=PressRight}********
<div class="row justify-content-center no-gutters press-black mb-5 mb-lg-0">
<div class="col-lg-6">
<div class="bg-black text-center h-100 project">
<div class="d-flex h-100">
<div class="project-text w-100 my-auto text-center text-lg-left">
{if $entry->summary}
<h4 class="text-white">
{$entry->title}
</h4>
<p class="mb-0 text-white-50">
{$entry->summary}
</p>
<hr class="d-none d-lg-block mb-0 ml-0">
{/if}
{if isset($entry->extra)}
<div class="NewsSummaryExtra">
{$entry->extra}
{cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue}
</div>
{/if}
</div>
</div>
</div>
</div>
<div class="col-lg-6">
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="text-center">
{if $field->type == 'file'}
{if isset($field->value) && $field->value}
<img class="img-fluid" src="{$entry->file_location}/{$field->value}"/>
{/if}
{elseif $field->type == 'linkedfile'} {* also assume it's an image... *}
{if !empty($field->value)}
<img class="img-fluid" src="{file_url file=$field->value}" alt="{$field->value}"/>
{/if}
{else}
{/if}
</div>
{/foreach}
{/if}
</div>
</div>
{/foreach}
<!-- End News Display Template -->
The way I see it, the first syntax "{foreach from=$items item=entry}" should have some additional formatting based on category like "{foreach from=$items item=entry category=PressLeft}" while the second one should call for output based on the category "PressRight" - something like {elseif item=entry category=PressRight}.
And that's where I got stuck and can't make it work. But the main question I'm asking is - is it possible to do something like this?
Thank you in advance for suggestions and help!
jakovbak