Try to think about the logic you need in normal language and then translate that to code:
"I want to know if the entry is in the 'Social Media' category."
code (untested):
Code: Select all
{$is_socialmedia = false}
{foreach from=$entry->categories item='category'}
{if $category.name == 'Social Media'}
{$is_socialmedia = true}
{break}
{/if}
{/foreach}
Rest of the code:
Code: Select all
{if $is_socialmedia}
<div class="CGBlogSummaryLink">
<h4>{$entry->title|escape}</h4>
</div>
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="CGBlogSummaryField">
{if $field->type == 'image_select'}
<img src="{CGSmartImage notag="1" src="{uploads_url}/{$field->value}" filter_croptofit="330,330,c"}"/>
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
{else}
<div class="CGBlogSummaryLink">
<h4><a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">{$entry->title|escape}</a></h4>
</div>
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="CGBlogSummaryField">
{if $field->type == 'image_select'}
<a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">
<img src="{CGSmartImage notag="1" src="{uploads_url}/{$field->value}" filter_croptofit="330,330,c"}"/>
<span class="image-overlay">
<span class="overlay-icon"><i class="fa fa-file-text"></i></span>
</span>
</a>
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
{/if}
You could even use the variable in more places to make the template smaller and less repeating code. But that's up to you:
Code: Select all
<div class="CGBlogSummaryLink">
{if $is_socialmedia}
<h4>{$entry->title|escape}</h4>
{else}
<h4><a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">{$entry->title|escape}</a></h4>
{/if}
</div>
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
<div class="CGBlogSummaryField">
{if $field->type == 'image_select'}
{if $is_socialmedia}
<a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">
{/if}
<img src="{CGSmartImage notag="1" src="{uploads_url}/{$field->value}" filter_croptofit="330,330,c"}"/>
{if $is_socialmedia}
<span class="image-overlay">
<span class="overlay-icon"><i class="fa fa-file-text"></i></span>
</span>
</a>
{/if}
{else}
{$field->name}: {eval var=$field->value}
{/if}
</div>
{/foreach}
{/if}
Now we're at it I want to give you a tip about the use of fields in a smarty template.
I see you're using the code from the sample template that comes with the module:
Code: Select all
{if isset($entry->fields)}
{foreach from=$entry->fields item='field'}
Be aware that a sample template doesn't know what field definitions a website builder will add, so it has no choice but using a foreach loop to work.
BUT, you are the website builder and you DO know what fields you've added. Also you know if/what fields are required to be filled by an editor. AND you know of what type a specific field is (file, image, text, etc.).
So, don't go for the inefficient and hard to read 'foreach' approach but just build your template in the layout you want, using the fields you have. (You're already doing it with the title. The title is a required field and always present, that's why it is used like that in the sample templates).
The template code will be easier to read as it looks more like the html output. Also it will be easier to convert an existing html template to a CMSMS module template this way.
Further, the order of the fields in the back end is not relevant for the output on the front end.
I don't know your field aliases so the code below is just an example (using the fictive aliases 'image' and 'description' for your fields).
Code: Select all
<div class="CGBlogSummaryLink">
{if $is_socialmedia}
<h4>{$entry->title|escape}</h4>
{else}
<h4><a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">{$entry->title|escape}</a></h4>
{/if}
</div>
<div class="CGBlogSummaryField">
{if $is_socialmedia}
<a href="{$entry->detail_url}" title="{$entry->title|escape:htmlall}">
{/if}
<img src="{CGSmartImage notag="1" src="{uploads_url}/{$entry->fields['image']->value}" filter_croptofit="330,330,c"}"/>
{if $is_socialmedia}
<span class="image-overlay">
<span class="overlay-icon"><i class="fa fa-file-text"></i></span>
</span>
</a>
{/if}
</div>
<div class="CGBlogSummaryField">
{$entry->fields['description']->value}
</div>
Looking at your screenshot I think you may already be using this logic.