Jump to content
louisstephens

Get Image Url in nested repeater

Recommended Posts

Ill be honest, I am a bit unsure how accomplish this. I have a repeater (dev_repeater) that contains an image field set to 1 image. Nested within this repeater, is another repeater (dev_child_repeater) that allows a user to add in some urls. However, there is also a hidden field that I am trying to pass the parent repeater's image path. 

I know I can output all the data by using:

<?php
	foreach($page->dev_repeater as $repeater) {
		foreach($repeater as $url) {
			# do some stuff
		}
	}
?>

For the life of me, I can not figure out how to obtain the image url in my php to pass to a variable inside the nested foreach loop. Hopefully this made some sense.

Share this post


Link to post
Share on other sites
<?php
	foreach($page->dev_repeater as $repeater) {
		$image_field = $repeater->image_field;
		foreach($repeater->dev_child_repeater as $url) {
			$url->hidden_field = $image_field->url;
		}
	}
?>

I´m guessing something like this should be working right?

Share this post


Link to post
Share on other sites

Hi,

this is not so clear to me in part "pass variable to hidden input"?
If need to save image path value to hidden input, than maybe it's better to go with hook in backend (after page save or other).
Another option coud be to save image path value to hidden input in runtime (???), if that is the case, than try something like this:

<?php
	foreach($page->dev_repeater as $repeater) {
		$image_field = $repeater->image_field;
		foreach($repeater->dev_child_repeater as $url) {
			
			// some other stuff, link etc...
			
			// check and save hidden_field value inside runtime (???)			
			if($url->hidden_field == ""){							
				$url->of(false);
				// $url->save(); uncomment if save on second reload
				$url->hidden_field = $image_field->url; // <= this?
				$url->save('hidden_field');		
			} else {
				// hidden_field has some value
				echo $url->hidden_field;
			}
		}
	}
?>

But also if there is any option to avoid nested repeater that would be better, and also try to think about using hooks in backend to avoid save in runtime. To me it's ok when need to save "page view counters" or some other events triggered by front-end users/vistors.
Sorry if I don't understand your question well.

Regards.

Share this post


Link to post
Share on other sites

Sorry @OLSA for the confusion. I was pretty frustrated and my question probably got garbled. Hopefully I can clear up what I am trying to do, as I switched gears a bit now that I have had time to think.

The setup: 

1. Repeater - dev_repeater
    - Image field (set to allow one) - dev_image
2. Nested Repeater - dev_button_repeater
	- Text Field - URL text to display on front-end
    - URL Field - dev_url
        - allows user to enter url (ie http://google.com), but if the item needs a data-attribute (for some ajax request), then they can use a hanna code [[data]] to add the attribute to the URL on the front end

I guess what I am trying to do, in the hanna code, is get the image url so it can be present in the data attribute. Perhaps a nested repeater is not the way to go, but I didnt know of another way to allow the user to "add" multiple items all with different values.

Share this post


Link to post
Share on other sites

The $page inside the Hannah code should refer to dev_button_repeater item, so you can search where it belongs to like this:

wire('pages')->get(preg_replace("for-page-",$page->name));

That should return the dev_repeater item of the iteration. 

Thoug  don't have very clear how you are using the hannah code. Maybe like this it would work?

Use the parent repeater's image if attr is data-image and no value is set.

[[data attr="data-image"]]

Set a custom data attribute:

[[data attr="data-example" value="Something something"]]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By David Karich
      ProcessWire InputfieldRepeaterMatrixDuplicate
      Thanks to the great ProModule "RepeaterMatrix" I have the possibility to create complex repeater items. With it I have created a quite powerful page builder. Many different content modules, with many more possible design options. The RepeaterMatrix module supports the cloning of items, but only within the same page. Now I often have the case that very design-intensive pages and items are created. If you want to use a content module on a different page (e.g. in the same design), you have to rebuild each item manually every time.
      This module extends the commercial ProModule "RepeaterMatrix" by the function to duplicate repeater items from one page to another page. The condition is that the target field is the same matrix field from which the item is duplicated. This module is currently understood as proof of concept. There are a few limitations that need to be considered. The intention of the module is that this functionality is integrated into the core of RepeaterMatrix and does not require an extra module.
      Check out the screencast
      What the module can do
      Duplicate a repeater item from one page to another No matter how complex the item is Full support for file and image fields Multilingual support Support of Min and Max settings Live synchronization of clipboard between multiple browser tabs. Copy an item and simply switch the browser tab to the target page and you will immediately see the past button Support of multiple RepeaterMatrix fields on one page Configurable which roles and fields are excluded Duplicated items are automatically pasted to the end of the target field and set to hidden status so that changes are not directly published Automatic clipboard update when other items are picked Automatically removes old clipboard data if it is not pasted within 6 hours Delete clipboard itself by clicking the selected item again Benefit: unbelievably fast workflow and content replication What the module can't do
      Before an item can be duplicated in its current version, the source page must be saved. This means that if you make changes to an item and copy this, the old saved state will be duplicated Dynamic loading is currently not possible. Means no AJAX. When pasting, the target page is saved completely No support for nested repeater items. Currently only first level items can be duplicated. Means a repeater field in a repeater field cannot be duplicated. Workaround: simply duplicate the parent item Dynamic reloading and adding of repeater items cannot be registered. Several interfaces and events from the core are missing. The initialization occurs only once after the page load event Changelog
      1.0.4
      Bug fix: Various bug fixes and improvements in live synchronization Bug fix: Items are no longer inserted when the normal save button is clicked. Only when the past button is explicitly clicked Feature: Support of multiple repeater fields in one page Feature: Support of repeater Min/Max settings Feature: Configurable roles and fields Enhancement: Improved clipboard management Enhancement: Documentation improvement Enhancement: Corrected few typos #1 1.0.3
      Feature: Live synchronization Enhancement: Load the module only in the backend Enhancement: Documentation improvement 1.0.2
      Bug fix: Various bug fixes and improvements in JS functions Enhancement: Documentation improvement Enhancement: Corrected few typos 1.0.1
      Bug fix: Various bug fixes and improvements in the duplication process 1.0.0
      Initial release Support this module
      If this module is useful for you, I am very thankful for your small donation: Donate 5,- Euro (via PayPal – or an amount of your choice. Thank you!)
      Download this module
      > Github: https://github.com/FlipZoomMedia/InputfieldRepeaterMatrixDuplicate
      > PW module directory: https://modules.processwire.com/modules/inputfield-repeater-matrix-duplicate/
    • By gerritvanaaken
      Wouldn’t it be cool to have whole repeater items (or even repeater matrix items) language-specific. Some of my clients do have pages that are 90% identical in German and English, but there are some sections that should not appear in one or another language. I attached a concept screenshot.
      Would something like this be possible with some simple backend hooks and "hidden checkbox fields"? Or is it way more complicated?
       

    • By Martin Wuehr
      Hello everybody,
      I'm hosting a Processwire Installation for a client. It runs on Processwire 2.5.3. Over the years everything was fine but now there is an issue with one Image-Field in one Template. Trying to upload an Image the Error "Not enough Memory to load/resize" occure. Other Image-Fields in all other Templates working without any issue. The Images I Tried to upload are very small (600px * 420px). The Images blongs to a News feed, and worked before.
      I read about the problem in the forum but I can't get this solved. I have no access to the php.ini to modify the memory_limit.
      I tried to update the Processwire Verion but failed. (Tried 2.7 /2.8 / 3.2) Got Always Internal Server Error and in the error Log: 
      Compile Error:     Cannot redeclare PageEditFieldPermissionConfig()….
      Has anybody any idea how I can get this solved?
      Thank you so much
      Martin
       
    • By August
      Hi again, after trying pages2PDF, RockPDF and mpdf I'm not sure which of them I should use. Of course, there is also wirePDF.
      I merged mpdf with rockPDF, add a footer and a page in Landscape and that works, like in the code-snippet below but be am I on the right way?
      After that I tried a couple of times rendering an image. Nothing happend, the same with Pages2PDF too. I also copied an Image-URL within processwire and tried further getting an Image within the PDF-Document, but it still display only the red marked placeholder.
      I simply would like create an PDF on click from some Pages including the Images.
      Are there special requirements on Debian 10 with Apache and php 7.3 using Processwire 3.0.123.?
      Is there a guide that I didn't found?
      Is somebody out there who has a similar issue solved and would you be so kind to explain?
       
      $pdf = $modules->get('RockPdf'); $mpdf = $pdf->mpdf; # $mpdf->showImageErrors = true; $pdf->set('SetHeader', 'header text'); $mpdf->AddPage('L'); # $mpdf->Image(urlencode('site/assets/files/1845/image-2.275x200.jpg'), 0, 0, 210, 297, 'jpg', '', true, false); $pdf->set('SetFooter', ' <table width="100%"> <tr> <td width="33%">{DATE j.m.Y}</td>        <td width="33%" align="center">{PAGENO}/{nbpg}</td> <td width="33%" style="text-align: right;">whatever</td> </tr> </table>'); $pdf->show(); // generate pdf  
    • By brdje
      Greetings,
       
      I've ran into an issue with adding a repeater field to a template.
      The page editor in the backend shows the fields and the data attached to the fields, including the repeater.
       
       
      However, when viewing the template in the front-end, there is no sign of a repeater field in the data set.
      ["data"]=> array(3) { ["name1189"]=> string(11) "partenaires" ["status1189"]=> string(1) "1" ["title"]=> string(8) "Partners" } } Do u have any idea what could be causing this issue?
      I've tried recreating the field and there is no caching active, but still can't get the repeater in the data set.
×
×
  • Create New...