Jump to content

Pages - Block Code Help


Recommended Posts

Hi all! We'd like to add the Grid View of recent "Blog" entries as a placeable Pages block. Was hoping the following would work, but all I'm getting is "No Story Entries Yet" (We've renamed the module Stories, and use it for user-written Literature). Any help would be amazing, thanks! We're on the latest 4.4.10.

{expression="\IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_browse.js', 'story'))"}
<section class='ipsType_normal ipsSpacer_both cBlog_grid' data-controller='blog.front.browse.grid'>
	{{if \count($entries)}}		
		{{$count = 0;}}
		{{if $pagination['page'] == 1}}
			<div class='cBlog_grid_row cBlog_grid_row--primary'>
				{{foreach $entries as $id => $entry}}
					{{if $count == 2}}
						{{break;}}
					{{endif}}

					{template="indexGridEntry" app="blog" location="front" group="browse" params="$entry, true"}
					{{$count++;}}
				{{endforeach}}
			</div>
		{{endif}}

		{{$count = 1;}}
		{{$subcount = 0;}}
		<div class='cBlog_grid_row'>
			{{foreach $entries as $id => $entry}}
				{{$subcount++;}}
				{{if ( $pagination['page'] == 1 and $subcount > 2 ) or ( $pagination['page'] > 1 and $subcount)}}
					{template="indexGridEntry" app="blog" location="front" group="browse" params="$entry"}
					{{if $count % 3 == 0}}
						</div>
						<div class='cBlog_grid_row'>
					{{endif}}
					{{$count++;}}
				{{endif}}
			{{endforeach}}
		</div>
	{{else}}
		<div class="ipsBox ipsType_center ipsPad">
			<p class="ipsType_large">{lang="no_entries_yet"}</p>
		</div>
	{{endif}}

 

Link to comment
Share on other sites

On 5/10/2020 at 5:08 AM, Sonya* said:

This {{if \count($entries)}}  returns NULL or 0. Try this:


{{if !empty( $entries ) }}

I have difficulties with count in the template. The variables seem to be not numeric (countable) so that count does not always work.

Unfortunately didn't work. I also tried changing the following $count = 0 to $entries = 0, with no luck there either.

Link to comment
Share on other sites

5 hours ago, AlexWright said:

 I also tried changing the following $count = 0 to $entries = 0, with no luck there either.

That would essentially delete your blog entries. Sonya provided the correct code to check for entries. But that has nothing to do with your internal counter. 

I would always start with IPS’ block template and modify it step by step, instead of taking code from somewhere else that probably doesn’t work in a block. I see other problems too, like that $pagination variable, which should also fail in a block. 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...