Print Link using Icon

About the template and stylesheet - and changing the menu
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Print Link using Icon

Post by cmb » Wed Sep 18, 2013 9:11 pm

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)
Last edited by cmb on Thu Sep 19, 2013 7:06 pm, edited 4 times in total.
Reason: added PS and PPS and PPPS
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3588
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Print Link using Icon

Post by Tata » Thu Sep 19, 2013 1:40 pm

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 >>>
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Print Link using Icon

Post by cmb » Thu Sep 19, 2013 2:40 pm

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.
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3588
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Print Link using Icon

Post by Tata » Thu Sep 19, 2013 3:05 pm

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>
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Print Link using Icon

Post by cmb » Thu Sep 19, 2013 3:51 pm

Oops, I should have looked more closely. I had posted the wrong function, sorry. I have fixed it now in the first post.
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3588
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Print Link using Icon

Post by Tata » Thu Sep 19, 2013 5:09 pm

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.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Print Link using Icon

Post by cmb » Thu Sep 19, 2013 7:13 pm

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.
Christoph M. Becker – Plugins for CMSimple_XH

Tata
Posts: 3588
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: Print Link using Icon

Post by Tata » Thu Sep 19, 2013 9:49 pm

Thanks, the template for download is actualized and both codes are included in it (one of them commented out.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Print Link using Icon

Post by cmb » Thu Sep 19, 2013 11:20 pm

Thanks. I have already updated the template for CMSimple_XH 1.5.10 and will keep an eye on it for XH 1.6.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply