General developer forum

php img src

 
Picture of Karlis Murans
php img src
 

Hi!

im trying to add a logo to the banner of my theme and all i get is the broken image icon, pls help.


 <a class="brand"

               href="<?php echo $CFG->wwwroot;?>">

                 <?php 

                echo "<img src='https://btrixkmrtest01.airbaltic.com/pix/logo.png' style='float:left; padding: 10px;' />";

                ?></a>


this is what i found on the internet as the way to do it, but it doesn't work for me.

full source is 

/var/www/abletest/theme/ab/pix/logo.png

tried also:


<a class="brand"

               href="<?php echo $CFG->wwwroot;?>">

                 <?php 

                echo "<img src='/var/www/abletest/theme/ab/pix/logo.png' style='float:left; padding: 10px;' />";

                ?></a>



pls help!

tnx in advance

 
Average of ratings: -
Picture of Richard Oelmann
Re: php img src
 
Average of ratings: -
Picture of Karlis Murans
Atbilde: Re: php img src
 

could you elaborate, because the part that should work doesn't, or mybe im just too retarded with php

 
Average of ratings: -
Picture of Richard Oelmann
Re: Atbilde: Re: php img src
Core developersParticularly helpful MoodlersPlugin developersTesters

Hmmm - it seems someone has replaced the 'Use in your layout file' section with the way to use them in Templates without leaving the previous version for those many people not using Boost and mustache templates yet, but it would seem from your code that you are not using that newer theming style.


In your theme

<a class="brand" href="<?php echo $CFG->wwwroot;?>">
    <img src="<?php echo $OUTPUT->pix_url('logo', 'theme'); ?>" alt="banner image" style='float:left; padding: 10px;'/>
</a>


Previous version of that linked page - for older themes (Clean based)

Using your images within your layout files

To use logo.jpg within the header of the layout file, open the layout file e.g. general.php and find the correct spot to put your logo.

....
<div id="page-header" class="clearfix">
    <!-- Logo should go here -->
    <h1 class="headermain"><?php echo $PAGE->heading ?></h1>
    <div class="headermenu"><?php
        echo $OUTPUT->login_info();
        echo $OUTPUT->lang_menu();
        echo $PAGE->headingmenu;
    ?></div>
</div>
....

To achieve this I simply need to add the following line of code:

<img src="<?php echo $OUTPUT->pix_url('logo', 'theme'); ?>" alt="" />

As before, the image's file extension is not needed as Moodle finds it automatically.

Combined the solution is very simple:

....
<div id="page-header" class="clearfix">
    <img src="<?php echo $OUTPUT->pix_url('logo', 'theme'); ?>" alt="" />
    <h1 class="headermain"><?php echo $PAGE->heading ?></h1>
    <div class="headermenu"><?php
        echo $OUTPUT->login_info();
        echo $OUTPUT->lang_menu();
        echo $PAGE->headingmenu;
    ?></div>
</div>
....

The only other thing to consider is how this example would look if logo.jpg was located in a subfolder e.g. pix/myimages/logos/logo.jpg.

The code for this would be:

<img src="<?php echo $OUTPUT->pix_url('myimages/logos/logo', 'theme'); ?>" alt="" />

Note that 'theme' above means the word theme, and not the name of your theme


 
Average of ratings: Useful (1)
Picture of Karlis Murans
Atbilde: Re: Atbilde: Re: php img src
 

Thanks a lot! this finally worked

 
Average of ratings: -