Jump to content

Recommended Posts

Posted

Do you mean in your template file? If so, you can do:

<img src="<?php echo $page->header->url; ?>" alt="<?php echo $page->header->description; ?>" />

This will get the url of the header image and allow you to out put the image for the page.

Posted

Could you show an example of your template file where you are trying to output the header image? Also, is you "header" field set to single image or multiple images? If multiple, the example I gave will not work.

Posted

<?php namespace ProcessWire;

// basic-page.php template file 

// Primary content is the page's body copy
$content = $page->body; 

// If the page has children, then render navigation to them under the body.
// See the _func.php for the renderNav example function.
if($page->hasChildren) {
    $content .= renderNav($page->children);
}

// if the rootParent (section) page has more than 1 child, then render 
// section navigation in the sidebar (see _func.php for renderNavTree).
if($page->rootParent->hasChildren > 1) {
    $sidebar = renderNavTree($page->rootParent, 3); 
    // make any sidebar text appear after navigation
    $sidebar .= $page->sidebar; 
}

Posted

Go to the tab "Details", under "Maximum files allowed" enter 1.

Go to the tab "Actions" and assure to have ticked the checkbox of the template you want to have the header image in.

Posted

Turn on $config->debug in your site/config.php, then you get a better error message, that says what the problem is.

Look under details of your image field and then "formatted value". Is it set to automatic?

Is "Maximum files allowed" set to 0?

If so, try 

 

<img src="<?php echo $page->header->first()->url; ?>" alt="<?php echo $page->header->first()->description; ?>" />

That is because an array is returned if "Maximum files  allowed" is 0.

Posted
On 5/13/2019 at 8:35 PM, wish-fulfillment said:

// Primary content is the page's body copy
$content = $page->body; 

There are roughly three types of ("official") templating strategies in PW:

  • Direct output (php echo everything immediately)
  • Delayed output (what you seem to be using, i.e. output var $content just once)
  • Markup regions
22 minutes ago, jens.martsch said:

<img src="<?php echo $page->header->first()->url; ?>" alt="<?php echo $page->header->first()->description; ?>" />

 

If you really are using delayed output, you would have to rewrite this, e.g. like

$src = $page->header->first()->url;
$alt = $page->header->first()->description;
$content .= "<img src=\"$src\" alt=\"$alt\" />

Your header most likely comes before the main content (body), so you just have to figure out where to insert the above code. It may not be in the basic-page template file, but somewhere else. Note that $var = 'foo' will override anything else that came before, i.e. if you defined $content = 'your-header-code' before, $page->body will completely reset your $content variable, not append to it.

On 5/13/2019 at 8:35 PM, wish-fulfillment said:

$content = $page->body; 

 

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