News Module: Adding a Checkbox to display feature content

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
Locked
ohemstock
Forum Members
Forum Members
Posts: 10
Joined: Wed Oct 12, 2016 4:05 pm

News Module: Adding a Checkbox to display feature content

Post by ohemstock »

Hi All,

I have created a summary template in the form of a slideshow to display featured news articles, to sort the featured articles from the non-featured ones I have added a custom field definition called 'Featured', it is a checkbox.

I am now trying to use this field to define which articles make it into the slideshow - ie: only the more impactful ones have the 'Featured' value of true. To do this I thought it would be a simple case of adding this inside the foreach loop:

Code: Select all

{if $entry->fields.Featured->value == 'true'} [display formatted article summary here] {/if}
BUT, the template then just displays nothing!

I have checked that the custom field is 'public', and also tried to find the answer via other posts to the forum without success...

The {foreach} loop for the template was working fine without the {if} statement, and it currently looks like this:

Code: Select all

{foreach from=$items item=entry}
{if $entry->fields.Featured->value == 'true'}
<div style="background: url({$entry->file_location}/{$entry->fields.image_1->value}); background-size:100%; background-position:center;">
   <div class="grid_5 offset_7">
     <h3><a href="{$entry->moreurl}" title="{$entry->title}">{$entry->title}</a></h3>
     <p>{$entry->fields.slide_text->value}&nbsp<a href="{$entry->moreurl}">More >></a></p>
   </div>
</div>
{/if}
{/foreach}
Thanks in advance for any pointers on how to solve this...

I am using v 2.1.5
mebots
Forum Members
Forum Members
Posts: 44
Joined: Sun May 23, 2010 10:22 pm

Re: News Module: Adding a Checkbox to display feature conten

Post by mebots »

Hello,

If you change this:

Code: Select all

{if $entry->fields.Featured->value == 'true'}
to

Code: Select all

{if $entry->fields.Featured->value}
Is it then working?

to show the values you get back from ($items) use in top of your template the following line:

{$items|@print_r}
ohemstock
Forum Members
Forum Members
Posts: 10
Joined: Wed Oct 12, 2016 4:05 pm

Re: News Module: Adding a Checkbox to display feature conten

Post by ohemstock »

mebots wrote:Hello,

If you change this:

Code: Select all

{if $entry->fields.Featured->value == 'true'}
to

Code: Select all

{if $entry->fields.Featured->value}
Is it then working?

to show the values you get back from ($items) use in top of your template the following line:

{$items|@print_r}
Hi, thanks for your response - just catching up after a New Year holiday..

I have altered the code as suggested but it doesn't work. The {if} statement seems to return no news articles. When I check the HTML, the container div is there but the slides (wrapped in the foreach loop) are not!

I have checked that I have articles with the new checkbox in 'true' state also (just to make sure I didn't miss the most obvious reason!)
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: News Module: Adding a Checkbox to display feature conten

Post by Rolf »

Code: Select all

{if $entry->fields.Featured->value == '1'}
   ...
{/if}
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
ohemstock
Forum Members
Forum Members
Posts: 10
Joined: Wed Oct 12, 2016 4:05 pm

Re: News Module: Adding a Checkbox to display feature conten

Post by ohemstock »

Rolf wrote:

Code: Select all

{if $entry->fields.Featured->value == '1'}
   ...
{/if}
Thanks Rolf, but that is not working either.

Here is this whole code for the summary template (minus the JS config stuff)

Code: Select all

<div class="slidebox">
<div id="slides">
<div class="slidesjs-navigation"><ul><li><a href="#" class="slidesjs-next slidesjs-navigation"></a></li><li><a href="#" class="slidesjs-previous slidesjs-navigation"></a></li></ul></div>
{foreach from=$items item=entry}
{if $entry->fields.Featured->value == '1'}
<div style="background: url({$entry->file_location}/{$entry->fields.image_1->value}); background-size:100%; background-position:center;">
   <div class="grid_5 offset_7">
     <h3><a href="{$entry->moreurl}" title="{$entry->title}">{$entry->title}</a></h3>
     <p>{$entry->fields.slide_text->value}&nbsp<a href="{$entry->moreurl}">More >></a></p>
   </div>
</div>
{/if}
{/foreach}
</div>
</div>
And this is what gets returned for the checkbox when I query {$items}

Code: Select all

[Featured] => news_field Object ( [_data:news_field:private] => Array ( [id] => 7 [name] => Featured [type] => checkbox [max_length] => 255 [item_order] => 7 [public] => 1 [extra] => a:1:{s:7:"options";N;} [value] => ) [_displayvalue:news_field:private] => )
mebots
Forum Members
Forum Members
Posts: 44
Joined: Sun May 23, 2010 10:22 pm

Re: News Module: Adding a Checkbox to display feature conten

Post by mebots »

Hello,

Do you have create this field Featured after you already have added news items?

If so you must walk through all news items and save them again, because the value of the Featured field doesn't exist in the table.

See following code: Featured was made before filling news, Featured_after was made after I have already added news items, you can see the value is empty instead of 0 or 1.

Code: Select all

[fields] => Array
                (
                    [Featured] => news_field Object
                        (
                            [_data:news_field:private] => Array
                                (
                                    [id] => 1
                                    [name] => Featured
                                    [type] => checkbox
                                    [max_length] => 255
                                    [item_order] => 1
                                    [public] => 1
                                    [extra] => a:1:{s:7:"options";N;}
                                    [value] => 0
                                )

                            [_displayvalue:news_field:private] => 
                        )

                    [Featured_after] => news_field Object
                        (
                            [_data:news_field:private] => Array
                                (
                                    [id] => 2
                                    [name] => Featured_after
                                    [type] => checkbox
                                    [max_length] => 255
                                    [item_order] => 2
                                    [public] => 1
                                    [extra] => a:1:{s:7:"options";N;}
                                    [value] => 
                                )

                            [_displayvalue:news_field:private] => 
                        )

                )
The code of Rolf and you is working correct.
Locked

Return to “Layout and Design (CSS & HTML)”