Last active
December 16, 2015 06:39
-
-
Save drmmr763/5393238 to your computer and use it in GitHub Desktop.
Example of how to use PHP functions in template.php in sobipro template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl"> | |
<xsl:template match="/entry_details"> | |
<xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/> | |
<xsl:variable name="title"><xsl:value-of select="entry/name" /></xsl:variable> | |
<h1><xsl:value-of select="php:function('RanchBrokers::PrettyTitle', $title)" disable-output-escaping="yes"/></h1> | |
</xsl:template> | |
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public static function PrettyTitle($txt) | |
{ | |
$txt = explode (" ", $txt); | |
$first_word = "<em>" . $txt[0] . "</em>"; | |
if (count($txt) > 0) { | |
unset($txt[0]); | |
$rest = ""; | |
foreach ($txt as $word) { | |
$rest .= " " . $word; | |
} | |
$PrettyTitle = $first_word . $rest; | |
} | |
else { | |
$PrettyTitle = $first_word; | |
} | |
return $PrettyTitle; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment