i have created this smarty plugin but i'm getting an error message whenever i try to use it.

<?php
    function smarty_modifier_prepare_link( $string, $link_type = 'http' ) {
        // use SSL
        if ( $link_type == 'http' && USE_SSL = 'no' )
            $link_type = 'http';
        switch( $link_type ) {
            case 'http' :
                $link = 'http://' . getenv( 'SERVER_NAME' );
                // If HTTP_SERVER_PORT is defined and different than default
                if ( defined( 'HTTP_SERVER_PORT' ) && HTTP_SERVER_PORT != '80' ) { // Append server port
                    $link .= ':' . HTTP_SERVER_PORT;
                }
                $link .= VIRTUAL_LOCATION . $string;
                return htmlspecialchars( $link, ENT_QUOTES ); // Escape html
            case 'https':
                $link = 'https://' . getenv( 'SERVER_NAME' ) . VIRTUAL_LOCATION . $string;
                return htmlspecialchars( $link, ENT_QUOTES );
            default:
                return htmlspecialchars( $string, ENT_QUOTES ); // Escape html
        }
    }

i'm trying to use it in a smarty template which has this code.

<div id="header">
    <a href="{"index.php"|prepare_link:"http"}">
        <img src="images/title.png" alt="Site title" />
    </a>
</div>

i'm getting an error that the modifier is unknown

Shouldn't that be:

<a href="{index.php|prepare_link:http}">

Smarty V3? I assume your script is in the right folder.

yes it's version 3. tried the code you suggested and it's now giving the following syntax error.

Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "C:\Apache24\htdocs\hatshop\presentation\templates\header.tpl" on line 3 "<a href="{index.php|prepare_link:http}">" - Unexpected ".", expected one of: "}" <-- thrown in C:\Apache24\htdocs\hatshop\libs\smarty\sysplugins\smarty_internal_templatecompilerbase.php on line 3

Hmz... Isn't this a variable modifier? So I think it should be like this:

<a href="{$URL|prepare_link:http}">

and then in code you need:

$tpl->assign('URL', 'index.php');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.