Jump to content
Sign in to follow this  
louisstephens

[SOLVED] Appending new item into foreach grid

Recommended Posts

From my last post, I was given a good idea on how to count the repeater items, and it worked wonderfully. I got my code working well and the columns (based on the count) all work well as well. Now, I have a head scratcher on my hands. 

<?php
	$buttonsIncluded = $page->special_custom_buttons->find('special_custom_buttons_include=1');
	$buttonsIncludedCount = count($buttonsIncluded);
	$buttonsIncludedCountAdditional = $buttonsIncludedCount +1;
	echo $buttonsIncludedCount;
?>

<div class="row">
	<?php foreach($buttonsIncluded as $button): ?>
	<?php if($button->custom_buttons_include): ?>
		<?php if($buttonsIncludedCountAdditional == 2): ?>
			<div class="col-6">
				<a href=""><?php echo $button->custom_buttons_text; ?></a>
			</div>
		<?php elseif($buttonsIncludedCountAdditional == 3): ?>
			<div class="col-4">
				<a href=""><?php echo $button->custom_buttons_text; ?></a>
			</div>
		<?php elseif($buttonsIncludedCountAdditional == 4): ?>
			<div class="col-3">
				<a href=""><?php echo $button->custom_buttons_text; ?></a>
			</div>

		<?php endif; ?>
	<?php endif; ?>
	<?php endforeach; ?>
</div>

All of this is included in a larger foreach statement that is pulling in other data (like body copy etc etc) from a Page Table field. As you can see in my code above, I am adding "1" to the count, so I can have space in the grid layout for a new button.

So, right now: it looks something like: 

[repeater button]		[repeater button]		[repeater button]		[space for new button]

What I really need to do is to pull in the button from the Page Table and add it into the new space so it looks like:

[repeater button]		[repeater button]		[repeater button]		[button from Page Table]

Is this even possible todo, or is there a better way to go about this? 

 

*Edit*

So, I really just overlooked something quite easy here. Since the grid is based on 12 columns, I could just take 12 and divide by $buttonsIncludedCountAdditional which would give me the remaining col width to use outside the foreach loop. I was trying to make this too complicated.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By quickjeff
      Hi Guys, 
      I have been debugging a site for the last 2 hours and cannot solve the issue. 
      I have a site running on 3.0.148. 
      I installed the Kongondo Blog module and was updating the templates to include the website style. 
      Once everything was set and done, I checked the page tree to see an error appear. 
      Template must be assigned a name before 'filename' can be accessed
      The same error appears in templates. 
      Debugging Steps
      I checked the templates in the server to ensure I didnt accidentally delete the namespace.  Deleted cache in browser and server under assets Still no go. 
      Any help is appreciated. 
      Thanks! 
    • By Spyros
      Hello
      I'm having a strange issue with the $page->find(), for some reason I'm missing some of the pages from the results. I found then that I was missing all the pages with the same "PAGE NAME". Is it a bug or am I missing something?
      PS 
      If I change the "PAGE NAME" of one of the missing ones then I'm retrieving the page without any problem.
      Thank you
    • By Guy Incognito
      This short script loops through some images from an XML feed and pushes new ones to an image field. It all works perfectly, except for some reason the last image (only) in the loop each time doesn't receive the image description... can everyone spot why? TIA! 🙂 
      foreach ($propertyImages as $img) { $fileName = trim($img[0]); if ( !empty($fileName) ) { $imgPath = '../property_data/'.$fileName; if(file_exists($imgPath) && !in_array(strtolower($fileName),$currentImages)) { $p->property_images->add($imgPath); $p->save(); $newImg = $p->property_images->last(); $newImg->description = $img[1]; $p->save(); } } }  
    • By MateThemes
      Hello everyone!
      I am working with Processwire since some time. But some topics are quite hard for me.
      I have a Portfolio (Gallery) Page.
      I am build a template with Portfolio Index and pages with portfolio entries.
      Structure:
      Portfolio Index
      -- Portfolio Entry
      -- Portfolio Entry
      and so on.
      Portfolio Entry has an Image field with max 12 images and are accessible Templates. 
      Now I want to display the single Portfolio Entry on the Portfolio Index and Paginate them. In the index page all images of a single Entry page should be displayed (I should not be organized as albums, where a random image of the portfolio entry should be displayed). 
      I have no clue to achieve this. May someone could give me an advice.
      Thank you in advance!
    • By Peter Knight
      I'm getting the following error. Having posted it in the GitHub I realise I should post it here instead.
      Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/domain.com/httpdocs/site/assets/cache/FileCompiler/site/modules/MarkupSEO/MarkupSEO.module on line 245 I know MarkupSEO is an old and relatively discontinued Module these days but was hoping to fix by upgrading both PHP and PW to latter versions.
      I am now running ProcessWire 3.0.148 © 2020 and PHP 7.3.13
      Issue persists.
×
×
  • Create New...