Jump to content

Open repeater item in another template


Roych
 Share

Recommended Posts

Hello

I need some help oppening repeater item in another template. I tried to look on forum but couldn't find anything helpful for me. 

I have repeater items for expl. team on my about page. And I would like to show more info about a single team member like (read more ...) with something like <?=$team->url?> or ...

I would create new template for team member.

Im showing my repeater list with:

		<?php foreach($page->ostali_sodelujoci_team as $team): ?>	
		<?php $image = $team->images->first;?>

					  <li class="grid-item post format-standard">
						<div class="team"> <a href="URL HERE?" > <img src="<?=$image->url; ?>" alt="<?=$image->description; ?>"> </a>
						  <div class="grid-content">
							<h3><a href="URL HERE?"><?=$team->title?></a></h3>
								<div class="naziv"><?=$team->team_naziv?></div>
								  <nav class="social-icons">
									<?php foreach ($team->team_social_repeater as $social):   ?>		
										<a href="<?=$social->URLassist; ?>" target="_blank"><i class="fa fa-<?=$social->home_info_blocks_icons; ?>"></i></a>
									<?php endforeach; ?>
								</nav>
                            <?php $summary = truncateText($team->body); echo "$summary ...";?> <a href="URL HERE?">Read more</a>
						  </div>
						</div>
					  </li>
              
            	<?php endforeach; ?>
           

Can this be done somehow with repeaters? I would really like to stay with repeater here if possible ofc.

Any help appreciated ?

R

 

Link to comment
Share on other sites

4 hours ago, Roych said:

Can this be done somehow with repeaters? I would really like to stay with repeater here if possible ofc.

Why?

It is possible using url segments, but I think it would be better to create pages. You have all the benefits that pages bring with them, like security (see RobinS post below!!), proper url handling, maybe page path history if enabled etc...

  • Like 3
Link to comment
Share on other sites

@Roych Repeater items are also pages, but they are hidden under admin page, so they don't have URLs, but you can use URL segments for that.

You should allow URL segments on you 'about' page template. 

Then you can construct URL based on team repeater item id or other fields inside repeater:

 <?php $summary = truncateText($team->body); echo "$summary ...";?> <a href="<?php echo $page->url($team->id); ?>">Read more</a>

Then on you about page template:

if ($input->urlSegment1) {
  
  $pagename = $input->urlSegment1;
  $match = $pages->get($sanitizer->int($pagename));
  if (!$match->id) throw new Wire404Exception();
  echo $match->render();
	
  return $this->halt();
}

----------

By the way you can use $sanitizer->truncate() to truncate your summery text

https://processwire.com/blog/posts/processwire-3.0.101-core-updates/

  • Like 4
Link to comment
Share on other sites

1 hour ago, Zeka said:

Then on you about page template:


if ($input->urlSegment1) {
  
  $pagename = $input->urlSegment1;
  $match = $pages->get($sanitizer->int($pagename));
  if (!$match->id) throw new Wire404Exception();
  echo $match->render();
	
  return $this->halt();
}

Good solution, but a couple of things:

1. It would be sensible to add a few restrictions about what page can be retrieved by the $pages->get(). The page ID is user input so potentially any page ID could be inserted into the URL allowing a user to see pages that they should not have access to: unpublished repeater pages, or indeed any page including admin pages could be rendered (although PW has extra checks here that would probably prevent anything sensitive from being disclosed).

Something like this would be safer:

$id = $sanitizer->int($input->urlSegment1);
$match = $pages->get("id=$id, template=repeater_your_repeater, status!=unpublished");

 

2. Calling $match->render() will only produce output if a template file exists for the repeater, which is normally not the case. It's possible to add a repeater template file but it might be easier to echo individual field values from $match.

  • Like 4
Link to comment
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
 Share

  • Recently Browsing   0 members

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