Page 1 of 1

Print Link using Icon

Posted: Wed Sep 18, 2013 9:11 pm
by cmb
Hello Community,

there are some templates that (want to) use an icon to display the link to the print view. By using the function printlink() this is not possible. Instead you can define an own function and call it appropriately. Just add the following function definition somewhere at the top of template.htm:

Code: Select all

<?php
function tpl_printurl() {
    global $f, $search, $file, $sn, $tx;
    $t = '&print';
    if ($f == 'search')
        $t .= '&function=search&search=' . htmlspecialchars(stsl($search), ENT_COMPAT, 'UTF-8');
    else if ($f == 'file')
        $t .= '&file=' . $file;
    else if ($f != '' && $f != 'save')
        $t .= '&' . $f;
    else if (sv('QUERY_STRING') != '')
        $t = htmlspecialchars(sv('QUERY_STRING'), ENT_COMPAT, 'UTF-8') . $t;
    return $sn . '?' . $t;
}
?>
Instead of

Code: Select all

<?php echo printlink();?>
now you can use the following for HTML 4.01 and 5 templates:

Code: Select all

<a href="<?php echo tpl_printurl();?>"><img src="..." alt="<?php echo $tx['menu']['print'];?>"></a>
resp. the following for (X)HTML conforming templates:

Code: Select all

<a href="<?php echo tpl_printurl();?>"><?php echo tag('img src="..." alt="' . $tx['menu']['print'] . '"');?></a>
Christoph

PS: I have already suggested to add a respective function to CMSimple_XH 1.6.

PPS: I have fixed the wrong function name in the first code division.

PPPS: For compatibility reasons I have replaced function XH_hsc() with htmlspecialchars() (XH_hsc() was introduced with CMSimple_XH 1.5.8 only)

Re: Print Link using Icon

Posted: Thu Sep 19, 2013 1:40 pm
by Tata
Two things:
cmb wrote: Just add the following function definition somewhere at the top of template.htm:

Code: Select all

<?php
function printlink() {...}?>
Instead of

Code: Select all

<?php echo printlink();?>
now you can use the following for HTML 4.01 and 5 templates:

Code: Select all

<a href="<?php echo tpl_printurl();?>"><img src="..." alt="<?php echo $tx['menu']['print'];?>"></a>
resp. the following for (X)HTML conforming templates:

Code: Select all

<a href="<?php echo tpl_printurl();?>"><?php echo tag('img src="..." alt="' . $tx['menu']['print'] . '"');?></a>
1. without renaming printlink() to tpl_printurl() the code doesn't work at all, of course.
2. with renamed function this is the result >>>

Re: Print Link using Icon

Posted: Thu Sep 19, 2013 2:40 pm
by cmb
Tata wrote:without renaming printlink() to tpl_printurl() the code doesn't work at all, of course.
You do not have to rename printlink() to tpl_printurl() only, but rather use one of the two code snippets I've listed above instead.

Re: Print Link using Icon

Posted: Thu Sep 19, 2013 3:05 pm
by Tata
Fatal error: Cannot redeclare printlink() in /Volumes/Localweb/cmsimple_XH_159/templates/structure1_black/template.htm on line 21

tried with:

Code: Select all

<a href="<?php echo tpl_printurl();?>"><?php echo tag('img src="print.png" alt="' . $tx['menu']['print'] . '"');?></a>

Code: Select all

<a href="<?php echo tpl_printurl();?>"><img src="<?php echo $pth['folder']['templateimages'];?>print.png" alt="<?php echo $tx['menu']['print'];?>"></a>

Code: Select all

<a href="<?php echo tpl_printurl();?>"><img src="<?php echo $pth['folder']['templateimages'].'print.png';?>"></a>

Re: Print Link using Icon

Posted: Thu Sep 19, 2013 3:51 pm
by cmb
Oops, I should have looked more closely. I had posted the wrong function, sorry. I have fixed it now in the first post.

Re: Print Link using Icon

Posted: Thu Sep 19, 2013 5:09 pm
by Tata
Ja, jetzt stimmt es mit dem 4.01 - 5 Code.
In dem zweiten habe ich problem das Bild zu definieren.

Hier ist die structure1_black mit der Funktion.

Re: Print Link using Icon

Posted: Thu Sep 19, 2013 7:13 pm
by cmb
You can use the following for (X)HTML conforming templates:

Code: Select all

<a href="<?php echo tpl_printurl();?>"><?php echo tag('img src="' . $pth['folder']['templateimages'] . 'print.png" alt="' . $tx['menu']['print'] . '"');?></a>
Please note, that I changed the tpl_printurl() function again for compatibility reasons.

Re: Print Link using Icon

Posted: Thu Sep 19, 2013 9:49 pm
by Tata
Thanks, the template for download is actualized and both codes are included in it (one of them commented out.

Re: Print Link using Icon

Posted: Thu Sep 19, 2013 11:20 pm
by cmb
Thanks. I have already updated the template for CMSimple_XH 1.5.10 and will keep an eye on it for XH 1.6.