Jump to content

URL shows only path and no filename.ext


olafgleba
 Share

Recommended Posts

Hi,

this might be a rather silly question, i am afraid.

I like to embed some blog entries from one PW installation into another (separate Domains/Servers). Nothing fancy,- i generate a plain php file in the origin installation, bootstrap PW and do a `$pages->find` to collect the desired entries, then output them in a foreach within this file.  To leave it simple, i will fetch the file with file_gets_contents() later within the target installation and output the delivered markup directely.

Everythings is fine, except that the `url` of the contained image field of an entry only outputs the path to the (correct) image asset folder. But without any filename and extension. And when i set `httpUrl`(which i will need later on the target installation) instead, the string is completely empty.

<? 
echo $item->test_image->url;

// Expected output: `/site/assets/files/98575/test_image.jpg`
// Actual output: `/site/assets/files/98575/`

echo $item->test_image->httpUrl;

// Expected output: `<full-path-to-server>/site/assets/files/98575/test_image.jpg`
// Actual output: ``
?>

I have done similiar things a lot, but i never run into such. And see no difference here. I am afraid, i overlook something very obvious. But don't get it since some hours.

cheers
Olaf

 

Link to comment
Share on other sites

When the fields are allowing multiple files, then you have to specify the "slot" (It is like an array, beginning with zero):

echo $page->images->eq(0)->url;

Also, possible the keywords 'first' and last:

echo $page->images->first()->url;

// Images and Files fields behave here the same.

Here are the settings in the field. You can also change that behavior:

image.thumb.png.b461de9dcf2e87eee5d355dccec109f1.png

  • Like 1
Link to comment
Share on other sites

Hi @Tiberium, thanks for your answer. Maximum number of files is set to `1`, Formatted value on `Automatic`. But nonetheless i tried it with the dedicaded array pointer. And see, there is the image! ;-).

While this is not neccessary if in a page template environment, i seem to forget regularly, that for fields which gets crawled in a PW bootstraped no formating/settings is available. Further example, output a date field (which has field format settings) shows up in a bootstraped file just a a raw timestamp. You must format this on place.

Thx again!

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