Jump to content

Recommended Posts

Posted (edited)

Hello i am new with processwire,

i cant have complete url of good images.
now i can have only image file name.


{$agent->title} are OK
but {$agent->images} src='image_name.jpg'
and {$agent->description} are empty
 


	<?php 
		if($page->id == 1) 
		$agents = $pages->get("/agents/")->children("limit=4");
		echo "<div class='row'>" ;
		foreach($agents as $agent) {
		echo "<div class='large-3 columns'>" .
		"<img class='img-circle' src='{$agent->images}' alt='{$agent->description}'>" .
                "<h4>{$agent->title}</h4>" .
                "<p>Bacon ipsum dolor sit amet nulla ham qui sint exercitation eiusmod commodo, chuck duis velit. Aute in reprehenderit, dolore aliqua non est magna in labore pig pork biltong. Eiusmod swine spare ribs reprehenderit culpa. Boudin aliqua adipisicing rump corned beef.</p>" .
               "</div>";
               }
               
 		?>
Edited by Astatek
Posted

HI Astatek and welcome to the forums.

By default, image fields can contain more than one image, so they will return an array of images, even if only one is uploaded. The simplest option is:

$agent->images->first()->url

but if you choose to change the setting on the image field's Details tab - "Max Files Allowed" to 1, then you could remove the need for the "first()". You can also adjust what will be returned when formatting is on by adjusting the "Formatted Value" options.

You should have a good read through http://processwire.com/api/fieldtypes/images/ to get a better understanding.

Hope that helps.

  • 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
  • Recently Browsing   0 members

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