Jump to content

image question


havana97
 Share

Recommended Posts

Depends on your use case, but.. that's not entirely true. When you embed an image into a CKEditor field, for an example, you get to choose from which page you want to pick the image from.

Similarly you can request an image from any given page via the API in your template files. So no, an image is not strictly tied to one page: you can embed images anywhere, and you can indeed use them in multiple places on your site. There are also some modules that make reusing media easier, such as MediaLibrary (free) and Media Manager (commercial).

It is true, though, that behind the scenes an image is always connected to a single page, and because of that ...

  • A) you can't have a single image showing up in image fields of multiple pages,
  • B) only one copy of each image file is stored in a page-specific directory under /site/assets/files/, and
  • C) if you have restricted access to a given page and enabled $config->pagefileSecure, access to files (including images) on that page will also be restricted.
  • Like 3
Link to comment
Share on other sites

Hi, and welcome,

You can get any image from any page with the $pages variable.

Basic use is like this: $image = $pages->get('/path/to/page/')->imagefield->
Examples:

$mypage = $pages->get('/path/to/mypage/');
$myimage = $mypage->images->get("name=myimage.jpg");

You can also use shorthand rules or hanna code to write more compact code

More here:
https://processwire.com/api/variables/pages/

 

  • Like 3
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...