Jump to content

Sharing images across pages


lindquist
 Share

Recommended Posts

Hi.

I've decided to use ProcessWire for the site I'm currently working on. I really like it so far!

My client needs a fairly standard informational site and a "blog" (really more like a news feature). So far things have come together nicely.

The designer I'm working with has provided me with a lot if graphics and I'm taking care of the coding side of things. Now, each page can have a "banner", basically a photo in the top, and some pages might share this banner.

Right now I'm simply using an Image field, and picking a random image from that for the banner. It works.

However, I'm thinking how to best make sure the same image resource gets used in the case that two (potentially unrelated) pages share the same banner... Right now I'm simply uploading the same banner image.

Could it be possible to somehow have a shared list of images, and then have a field "pointing" to a selection of these? I'm sure it can be done, but I'm not sure what the best course of action will be.

I'm quite experienced as a developer, but I'm new with PW, so I guess I'm mainly looking for some fairly specific pointers :)

Hope it makes sense, I'm sure I will have more questions in time :)

Thanks in advance

- Lindquist

  • Like 1
Link to comment
Share on other sites

For these header images, I use the images in the home page as fallback sometimes. (You could make a 2nd images field for this )

Or you setup a field with the type of page, and let them select where the header image is.

Then you could pick it up in your template.

$headerImages = $page->nameOfFieldTypePage->images; // Array with images (if images are provided)

  • Like 1
Link to comment
Share on other sites

I don't know if your intention was that one, but maybe you could create a new page (maybe with a template images/banners?) with only images as fields (or html codes for showing the image or maybe repeater) and load them at your wanted place. For this purpose, you could use something like this:

<?=$pages->get("/your_central_image_page/")->image1?>
  • Like 1
Link to comment
Share on other sites

Thank you for the suggestions. After giving this a bit more thought, basically what I'd like is:

A field type "SharedImages" which

1) has a "global" or "shared" list of images between each instance of the field and

2) allows each instantiation to make a selection of images from that shared list.

So two pages having a "SharedImages" field will show the same list of images, and have their own checkboxes or something to select which images they want to use.

Am I asking too much? :-P I guess I should take a look at how the images field is implemented...

Link to comment
Share on other sites

Then I think you should create a parent somewhere in the admin tree. And put pages in it with template with 2 fields. (template name header-image or something you like)

Field 1 = title

Field 2 = image field ( allow only 1 image to be upload in there )

The create a Field type of Page, select The parent & if you wish, select the template.

Put that field to the template from where you want to select the page that contains the header image.

Link to comment
Share on other sites

Have each "banner" a page with a template "banner" which contains an image field and possibly more fields for additional meta data. Create a template "banners" (only field title) and only allow children to have "banner" template. Create a page "Banners" using that template. Now create banners as subchilds of the Banners page.

THen create a page field "select_banner" and allow it to select pages with template "banner", and have the inputfield a simple select.

Attach "select_banner" to the template you would like to select a banner. Use that to render the image or whatever from the selected banner.

This is one way of doing it which has many advantages and allows for great simplicity and flexibility. Of course an dedicated field could be created, but I mostly prefer to do these thing as much as possibly using that approach.

  • Like 1
Link to comment
Share on other sites

Hi Soma and Martijn,

It seems you're both suggesting pretty similar solutions. I guess it's a decent way to go about it. The only "downside" I can think of is that the client does not see which "banner" is selected visually until previewing the page (ie. has to remember which banner are which pages). It's really minor.

Also this approac is very similar to what I'm already doing in a few other places, so I think I'll just go along with it.

Thanks for the input!

Link to comment
Share on other sites

It seems you're both suggesting pretty similar solutions. I guess it's a decent way to go about it. The only "downside" I can think of is that the client does not see which "banner" is selected visually until previewing the page (ie. has to remember which banner are which pages). It's really minor.

With a little trick you can get this to work. Install this module http://modules.processwire.com/modules/page-list-image-label/ and you'll see an image preview. If you then set the page field to select the input "PageListSelect" you'll be able to see the image label of the page. The PageListSelectMultiple select you'll only see the image when choosing from the tree.

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Wouldn't Processwire benefit from having some sort of global file/image management module so that you could choose assets for any page from a single location, rather than being specific to a page?

I'm working a site where the client has decided to use the same content image on more than one page. At the moment, it seems the only acceptable option would be to upload the same image more than once. Creating related pages just to be able to add the same image to more than one page seems overkill for this scenario.

On another site, the client wants to add images to the WYSIWYG field but first they have to add them to the page using the Images field on the page. It would be good if you could add images to a file module directly from within the WYSIWYG, because that two-step disjointed process is confusing for some people.

A lot of other CMS have global file managers/media libraries, so just wondering why that feature is missing from Processwire?

  • Like 2
Link to comment
Share on other sites

so that you could choose assets for any page from a single location, rather than being specific to a page?

It's been brought up before, this idea of site-wide image libraries. They remind me of a bucket-type system, and PW's page system is sort of the opposite. You'd end up with a hybrid-bucket system. :D What about this feature, which shows if you use the image button without loading any images? (bolding mine)

There are no images present on this page. Close this window and upload images, or select images from another page.

Link to comment
Share on other sites

@Tyssen 

That only works from within the WYSIWYG though right? Doesn't work if you want to add an image with the standard images field.

Correct 

One idea might be to modify the image field to allow you browse other page image fields(s) and then choose an existing image as a reference that would be rendered like a local image that is uploaded. 

Link to comment
Share on other sites

  • 2 months later...

That only works from within the WYSIWYG though right? Doesn't work if you want to add an image with the standard images field.

Yes, if there would be an option to choose one the existing images.

This would be very useful e.g. for an image gallery. I want to make it possible to select one of the existing images as the gallery thumbnail. Fot this selection a WYSIWYG field will be a bit "oversized"...

Link to comment
Share on other sites

Use page fields and youll be able to select a page image or a parent or multiple. ImagesManager doesnt restrict but help.

But if each gallery is a page and has a lot of images - it wouldn't be possible to choose one of the images, right? I would have to use a seperate page for each image.

Link to comment
Share on other sites

  • 4 years later...
On 25/11/2012 at 8:09 PM, Martijn Geerts said:

Then I think you should create a parent somewhere in the admin tree. And put pages in it with template with 2 fields. (template name header-image or something you like)

Field 1 = title

Field 2 = image field ( allow only 1 image to be upload in there )

The create a Field type of Page, select The parent & if you wish, select the template.

Put that field to the template from where you want to select the page that contains the header image.

Can't we just use the images field as input for a Page type field? Each image has a description that can be use as a title?

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...