Jump to content

why can't see header?


Recommended Posts

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.

Link to comment
Share on other sites

<?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; 
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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; 

 

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

×
×
  • Create New...