Page 1 of 1

How to separate News articles in output?

Posted: Wed Sep 29, 2021 7:16 pm
by jakovbak
Hello folks!
Is there a way to separate News articles in output? This is how it looks by default:

Code: Select all

<div class="newsarticles">
	<div class="newsimage"></div>
	<div class="NewsSummary"></div>
	<div class="newsimage"></div>
	<div class="NewsSummary"></div>
</div>
"newsimage" and "NewsSummary" come in pairs and they both belong to one News article. What I'm trying to achieve is this:

Code: Select all

<div class="newsarticles">
	<div class="newsimage"></div>
	<div class="NewsSummary"></div>
</div>
<div class="newsarticles">
	<div class="newsimage"></div>
	<div class="NewsSummary"></div>
</div>
In short, how could one make each article to be wrapped in separate <div> in output?

This is my NewsSummary template:

Code: Select all

<!-- Start News Display Template -->
<div class="newsarticles">

{foreach from=$items item=entry}

{* NEWS SUMMARY IMAGE - class="bi-pic" *}
	{if isset($entry->fields)}
		{foreach from=$entry->fields item='field'}
			<div class="bi-pic">
				{if $field->type == 'file'}
					{if isset($field->value) && $field->value}
						<img src="{$entry->file_location}/{$field->value}"/>
					{/if}
				{/if}
			</div>
		{/foreach}
	{/if}
{* NEWS SUMMARY IMAGE - class="bi-pic" - END FIELD *}

{* NEWS SUMMARY TEXT - class="bi-text" *}
	<div class="NewsSummary">
		<div class="bi-text">
			{* NEWS SUMMARY LINK/TITLE - class="bi-text" *}
			<h5><a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a></h5>
			{* NEWS SUMMARY AUTHIR/DATE/CATEGORY - class="bi-text" *}
			<ul>
				<li>{$author_label} {$entry->author}</li>
				<li>{$entry->postdate|cms_date_format}</li>
				<li>{$category_label} {$entry->category}</li>
			</ul>
			{if $entry->summary}
				<p>{$entry->summary}</p>
			{else if $entry->content}
				{$entry->content}
			{/if}
		</div>
	</div>
{* NEWS SUMMARY TEXT - class="bi-text" - END FIELD*}

	{if isset($entry->extra)}
		<div class="NewsSummaryExtra">
			{$entry->extra}
			{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
		</div>
	{/if}
{/foreach}

</div>
<!-- End News Display Template -->
Thank you in advance for any idea or direction you may come up with!
Bes regards,
jakovbak

Re: How to separate News articles in output?

Posted: Wed Sep 29, 2021 8:11 pm
by DIGI3
The {foreach}...{/freach} iterates through your news articles, so anything you want to appear for each article should be inside them. My guess is that you want to move the <div class="newsarticles"> and corresponding closing div inside the foreach loop.

Re: How to separate News articles in output?

Posted: Thu Sep 30, 2021 12:56 pm
by johnboyuk1
agreed.. like this:

Code: Select all


<!-- Start News Display Template -->


{foreach from=$items item=entry}
<div class="newsarticles">
{* NEWS SUMMARY IMAGE - class="bi-pic" *}
	{if isset($entry->fields)}
		{foreach from=$entry->fields item='field'}
			<div class="bi-pic">
				{if $field->type == 'file'}
					{if isset($field->value) && $field->value}
						<img src="{$entry->file_location}/{$field->value}"/>
					{/if}
				{/if}
			</div>
		{/foreach}
	{/if}
{* NEWS SUMMARY IMAGE - class="bi-pic" - END FIELD *}

{* NEWS SUMMARY TEXT - class="bi-text" *}
	<div class="NewsSummary">
		<div class="bi-text">
			{* NEWS SUMMARY LINK/TITLE - class="bi-text" *}
			<h5><a href="{$entry->moreurl}" title="{$entry->title|cms_escape:htmlall}">{$entry->title|cms_escape}</a></h5>
			{* NEWS SUMMARY AUTHIR/DATE/CATEGORY - class="bi-text" *}
			<ul>
				<li>{$author_label} {$entry->author}</li>
				<li>{$entry->postdate|cms_date_format}</li>
				<li>{$category_label} {$entry->category}</li>
			</ul>
			{if $entry->summary}
				<p>{$entry->summary}</p>
			{else if $entry->content}
				{$entry->content}
			{/if}
		</div>
	</div>
{* NEWS SUMMARY TEXT - class="bi-text" - END FIELD*}

	{if isset($entry->extra)}
		<div class="NewsSummaryExtra">
			{$entry->extra}
			{* {cms_module module='Uploads' mode='simpleurl' upload_id=$entry->extravalue} *}
		</div>
	{/if}
	</div>
{/foreach}


<!-- End News Display Template -->


Re: How to separate News articles in output?

Posted: Thu Sep 30, 2021 6:50 pm
by jakovbak
Yes! Thank you guys, this works like a charm and you saved my day!