Jump to content

Recommended Posts

Posted

I appreciate all the help thus far in learning how to navigate Processwire. However, I have hit a road block. I have an Image Field in one of my templates (it is being used in a repeater), and I would like to assign a preexisting page's url to the image .

Ie:

<a href="url-to-page"><img src="code-for-image" /></a> 

However, maybe I have missed something, as I set up the field (homepageImg) to be a "page select" but nothing is currently populating the dropdown. I am merely trying to get all the children of the parent (that the current page is in) and display them. I thought this would make it easy for someone to set the URL on the fly. Any help would be appreciated.

Posted

If I understand you correctly, you now need a parent page in the tree where all of your "page selects" are pulled from.  The child pages are what you see in your field (homepagimg).

An Example

post-756-0-48353300-1447197053_thumb.png

Posted

The following code snippet wraps an image with an anchor tag, if the first word of the image description matches a pagename of a page in your page tree

$image = $page->images->first();

$selector = strstr($image->description,' ',true)?strstr($image->description,' ',true):$image->description;
$selector = trim($selector,"\W"); // trim punctuation

$linkpage = $pages->get('name='.$selector.',has_parent!=2'); // modify selector for your needs
$anchor = $linkpage->id?"<a title=\"go to $linkpage->title\" href=\"$linkpage->url\">":null;

echo  "$anchor<img src=\"$image->url\" alt=\"$image->description\"/>".($anchor?'</a>':'');

to get all siblings of your page use

$pages->siblings($selector);
Posted

Thank you all for the quick responses. After rereading my original post, I think I need to clarify the issue. 

I have a repeater set up with:

Name

Image

PageUrl (this is the field set to a page field).

I thought by setting pageURL to a page field type, I could then select a page, and then pull that url using something similiar to what kixe describes. However, nothing is showing up in the actual dropdown. Is there a better way to allow a user to select a "url" to use for linking the image?

Posted

I've used URLs before but those URLs were in the page title and that's how they were retrievable in the dropdown.  You may be able to use an actual URL field and do the same thing.

Posted

Ah,

This repeater will be used on other pages as well, so I was trying to figure out a way for the url selection to be easy on the user without having to manual input the url for every page.

Posted

Maybe I am not understanding, but it should be as simple as returning this:

$homepageImg->url

Just make sure that the homepageImg field is set to "PageListSelect" without the "Multiple" and that the "Dereference in API as" is set to Single.

That should then return the URL to the page they selected.

Posted

Thanks Adrian. The idea in my head might not be coming out in the actual post as well as I intended. The basic set up is thus:

I have an Image field in my template as well as a field called 'imageURL' (all in a repeater). My hopes were that I could easily use a drop down to allow a user to change the url of the image on the fly without having to manually enter the information.

The page Structure I have is:

Home

 - Sub Page 1

   - Sub 'Sub' Page

   - Sub 'Sub' Page

   - Sub 'Sub' Page

   - Sub 'Sub' Page

   - Sub 'Sub' Page

 - Sub Page 1

 
 
For the url field, I was hoping to just grab the list of "Sub Sub Pages", and snag the url from that to link the image with.
Posted

I think I had the same problem recently. I'll trawl through a project I had in progress and see how I solved it.

You basically want to allow clients to apply a link to an image. The link around the image would direct front end users to an internal page.

On the Admin side, you're using the pageselect field to achieve this.

Any code examples and screenshots of the Admin for us?

Posted

Is this what you want to see?

post-985-0-75607000-1447356646.png

The other option would actually be to use the ImageExtra module and the link option - it will work like a pagelistselect, rather than a select dropdown, but would avoid the need for repeaters.

Posted

Thanks everyone. Adrian, that is what I am trying to achieve, and hopefully can extract the url from that. Ill try to get some pictures up to hopefully better explain. I do apologize for seeming so vague.

Posted

If my screenshot is what you want to achieve, then it's very easy. Here are the settings for the details tab of the field:

post-985-0-12881100-1447366695_thumb.png

And here is the page tree that is being referenced:

post-985-0-07075200-1447366770_thumb.png

  • Like 3
Posted

Ah ha.. That does the ticket. And now for something probably too confusing. I know this method would only work for this repeater on this page. However, what If I wanted to reuse this repeater and its fields on another page tree all together (without recreating the repeater everytime). 

Posted

Ah ha.. That does the ticket. And now for something probably too confusing. I know this method would only work for this repeater on this page. However, what If I wanted to reuse this repeater and its fields on another page tree all together (without recreating the repeater everytime). 

Depending on your setup, you could probably make use of the "Custom PHP code to find selectable pages" option and reference the $page->parent or $page->parent->parent - hopefully you get the idea.

  • Like 2
Posted

Perhaps a dumb question Adrian, I see that return $page->parent->parent(); returns the top level so:

- Sup Page 1

- Sup Page 2

- Sup Page 3

- Sup Page 4

How would I drill down and list all the children of the parent? I know about first();, but didnt know if there was an "All" selector.

I do appreciate all the help as I stumble through this.

Posted

Thanks Adrian. I actually had gotten to that point yesterday, but noticed it was still pulling in the parents.

I got it working with:

return $page->parent->children();
  • Like 1

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
×
×
  • Create New...